From 0286a7b0461d2a2be62c3600703fb98509cf0dd4 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 14 Sep 2016 10:12:44 +1000 Subject: [PATCH] Fixes #1131 --- .../stream/AbstractDelegateOutputStream.java | 38 +++++++++++++++++++ .../plot/util/MainUtil.java | 7 +++- .../plot/util/SchematicHandler.java | 10 ++--- .../nukkit/listeners/PlayerEvents.java | 9 +++-- 4 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/object/stream/AbstractDelegateOutputStream.java diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/stream/AbstractDelegateOutputStream.java b/Core/src/main/java/com/intellectualcrafters/plot/object/stream/AbstractDelegateOutputStream.java new file mode 100644 index 000000000..72091c59c --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/stream/AbstractDelegateOutputStream.java @@ -0,0 +1,38 @@ +package com.intellectualcrafters.plot.object.stream; + +import java.io.IOException; +import java.io.OutputStream; + +public class AbstractDelegateOutputStream extends OutputStream { + private final OutputStream parent; + + @Override + public void write(int b) throws IOException { + parent.write(b); + } + + @Override + public void write(byte[] b) throws IOException { + parent.write(b); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + parent.write(b, off, len); + } + + @Override + public void flush() throws IOException { + parent.flush(); + } + + @Override + public void close() throws IOException { + parent.close(); + } + + public AbstractDelegateOutputStream(OutputStream os) { + this.parent = os; + } +} + diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 9de9572ee..3fb03b31e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -16,6 +16,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.stream.AbstractDelegateOutputStream; import com.intellectualcrafters.plot.util.expiry.ExpireManager; import java.io.File; @@ -156,7 +157,11 @@ public class MainUtil { writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(filename)).append(CRLF); writer.append("Content-Transfer-Encoding: binary").append(CRLF); writer.append(CRLF).flush(); - writeTask.value = output; + OutputStream nonClosable = new AbstractDelegateOutputStream(output) { + @Override + public void close() throws IOException { } // Don't close + }; + writeTask.value = nonClosable; writeTask.run(); output.flush(); writer.append(CRLF).flush(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 1efbe047a..811ae8d23 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -527,11 +527,11 @@ public abstract class SchematicHandler { @Override public void run(OutputStream output) { try { - GZIPOutputStream gzip = new GZIPOutputStream(output, true); - NBTOutputStream nos = new NBTOutputStream(gzip); - nos.writeTag(tag); - nos.flush(); - gzip.flush(); + try (GZIPOutputStream gzip = new GZIPOutputStream(output, true)) { + try (NBTOutputStream nos = new NBTOutputStream(gzip)) { + nos.writeTag(tag); + } + } } catch (IOException e) { e.printStackTrace(); } diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/listeners/PlayerEvents.java b/Nukkit/src/main/java/com/plotsquared/nukkit/listeners/PlayerEvents.java index 2acd46080..0aeeed5ea 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/listeners/PlayerEvents.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/listeners/PlayerEvents.java @@ -29,6 +29,7 @@ import cn.nukkit.event.block.BlockSpreadEvent; import cn.nukkit.event.block.BlockUpdateEvent; import cn.nukkit.event.entity.EntityBlockChangeEvent; import cn.nukkit.event.entity.EntityCombustByEntityEvent; +import cn.nukkit.event.entity.EntityCombustEvent; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.event.entity.EntityExplodeEvent; @@ -148,9 +149,11 @@ public class PlayerEvents extends PlotListener implements Listener { } @EventHandler(priority = EventPriority.HIGHEST) - public void onEntityCombustByEntity(EntityCombustByEntityEvent event) { - EntityDamageByEntityEvent eventChange = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.CAUSE_FIRE_TICK, event.getDuration()); - onEntityDamageByEntityEvent(eventChange); + public void onEntityCombustByEntity(EntityCombustEvent event) { + if (event instanceof EntityCombustByEntityEvent) { + EntityDamageByEntityEvent eventChange = new EntityDamageByEntityEvent(((EntityCombustByEntityEvent) event).getCombuster(), event.getEntity(), EntityDamageEvent.CAUSE_FIRE_TICK, event.getDuration()); + onEntityDamageByEntityEvent(eventChange); + } } @EventHandler(priority = EventPriority.HIGHEST)