From c599e75fa6135e308e41c4f4c90f3892f23dff77 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 2 May 2016 13:19:25 +1000 Subject: [PATCH] Have NullExtent extend FaweRegionExtent instead (more uses) --- .../boydti/fawe/object/extent/NullExtent.java | 27 ++++++++++++------- .../java/com/boydti/fawe/util/WEManager.java | 2 +- .../java/com/sk89q/worldedit/EditSession.java | 8 +++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index c49415c9..39a3cdf2 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -15,16 +15,18 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nullable; -public class NullExtent implements Extent { +public class NullExtent extends FaweRegionExtent { private final BBC reason; /** * Create a new instance. + * + * @param extent the extent */ - public NullExtent(BBC failReason) { + public NullExtent(Extent extent, BBC failReason) { + super(extent); this.reason = failReason; } @@ -48,12 +50,6 @@ public class NullExtent implements Extent { throw new FaweException(reason); } - @Nullable - @Override - public Operation commit() { - return null; - } - @Override public boolean setBlock(final Vector arg0, final BaseBlock arg1) throws WorldEditException { throw new FaweException(reason); @@ -83,4 +79,17 @@ public class NullExtent implements Extent { public Vector getMinimumPoint() { return new Vector(0, 0, 0); } + + @Override + public boolean contains(int x, int y, int z) { return false; } + + @Override + protected Operation commitBefore() { + return null; + } + + @Override + public Extent getExtent() { + return this; + } } diff --git a/core/src/main/java/com/boydti/fawe/util/WEManager.java b/core/src/main/java/com/boydti/fawe/util/WEManager.java index c41d9c9d..75f5c9b5 100644 --- a/core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -26,7 +26,7 @@ public class WEManager { try { final Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); field.setAccessible(true); - field.set(parent, new NullExtent(reason)); + field.set(parent, new NullExtent((Extent) field.get(parent), reason)); } catch (final Exception e) { e.printStackTrace(); } diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index c8ac217e..a94c0678 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -225,7 +225,7 @@ public class EditSession implements Extent { // Invalid world: return null extent if (world == null) { - NullExtent extent = new NullExtent(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); + Extent extent = this.regionExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); this.bypassReorderHistory = extent; this.bypassHistory = extent; this.bypassNone = extent; @@ -284,7 +284,7 @@ public class EditSession implements Extent { mask = WEManager.IMP.getMask(fp); if (mask.size() == 0) { // No allowed area; return null extent - extent = new NullExtent(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); + extent = this.regionExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); this.bypassReorderHistory = extent; this.bypassHistory = extent; this.bypassNone = extent; @@ -309,7 +309,7 @@ public class EditSession implements Extent { BBC.WORLDEDIT_OOM_ADMIN.send(fp); } // Memory limit reached; return null extent - extent = new NullExtent(BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); + extent = this.regionExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); this.bypassReorderHistory = extent; this.bypassHistory = extent; this.bypassNone = extent; @@ -369,7 +369,7 @@ public class EditSession implements Extent { try { WEManager.IMP.cancelEdit(primaryExtent, BBC.WORLDEDIT_CANCEL_REASON_MANUAL); } catch (Throwable ignore) {} - NullExtent nullExtent = new NullExtent(BBC.WORLDEDIT_CANCEL_REASON_MANUAL); + NullExtent nullExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MANUAL); primaryExtent = nullExtent; dequeue(); queue.clear();