From 56d50bd9e12f4e3ed54c22e8ee26c6ad4560544a Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 28 Aug 2015 08:33:32 +1000 Subject: [PATCH] Fix masking extent + process non plot worlds --- .../plot/util/SetBlockQueue.java | 43 +++++++++++++++++-- .../bukkit/listeners/worldedit/WEManager.java | 6 +++ .../listeners/worldedit/WESubscriber.java | 34 +++++++++++---- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java b/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java index 3cbce1adb..431abe66e 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java +++ b/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java @@ -35,7 +35,7 @@ public class SetBlockQueue { public synchronized static boolean addNotify(Runnable whenDone) { if (runnables == null) { - if (blocks == null) { + if (blocks == null || blocks.size() == 0) { if (whenDone != null) { whenDone.run(); } @@ -46,8 +46,23 @@ public class SetBlockQueue { runnables = new ArrayDeque<>(); } if (whenDone != null) { + init(); runnables.add(whenDone); } + if (blocks == null || blocks.size() == 0) { + ArrayDeque tasks = runnables; + lastInt = -1; + lastBlock = null; + runnables = null; + running = false; + blocks = null; + slow = false; + if (tasks != null) { + for (Runnable runnable : tasks) { + runnable.run(); + } + } + } return false; } @@ -66,6 +81,7 @@ public class SetBlockQueue { @Override public void run() { if (locked) { + System.out.print("LOCKED!"); return; } if (blocks == null || blocks.size() == 0) { @@ -74,8 +90,8 @@ public class SetBlockQueue { lastInt = -1; lastBlock = null; runnables = null; - blocks = null; running = false; + blocks = null; slow = false; if (tasks != null) { for (Runnable runnable : tasks) { @@ -92,6 +108,19 @@ public class SetBlockQueue { } Iterator> iter = blocks.entrySet().iterator(); if (!iter.hasNext()) { + PS.get().TASK.cancelTask(TaskManager.tasks.get(current)); + ArrayDeque tasks = runnables; + lastInt = -1; + lastBlock = null; + runnables = null; + running = false; + blocks = null; + slow = false; + if (tasks != null) { + for (Runnable runnable : tasks) { + runnable.run(); + } + } return; } Entry n = iter.next(); @@ -196,7 +225,10 @@ public class SetBlockQueue { ChunkWrapper wrap = new ChunkWrapper(world, X, Z); PlotBlock[][] result; result = blocks.get(wrap); - if (!blocks.containsKey(wrap)) { + if (result == null) { + if (blocks == null) { + init(); + } result = new PlotBlock[16][]; blocks.put(wrap, result); } @@ -219,7 +251,10 @@ public class SetBlockQueue { ChunkWrapper wrap = new ChunkWrapper(world, X, Z); PlotBlock[][] result; result = blocks.get(wrap); - if (!blocks.containsKey(wrap)) { + if (result == null) { + if (blocks == null) { + init(); + } result = new PlotBlock[16][]; blocks.put(wrap, result); } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java index 3bed10e2b..0a977429c 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WEManager.java @@ -27,6 +27,12 @@ public class WEManager { public static HashSet getMask(PlotPlayer player) { HashSet regions = new HashSet<>(); UUID uuid = player.getUUID(); + Location location = player.getLocation(); + String world = location.getWorld(); + if (!PS.get().isPlotWorld(world)) { + regions.add(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE)); + return regions; + } for (Plot plot : PS.get().getPlotsInWorld(player.getLocation().getWorld())) { if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && FlagManager.getPlotFlag(plot, "done") != null)) { continue; diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java index b3dbd1fe7..a6284affa 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.ChangeSetExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.MaskingExtent; import com.sk89q.worldedit.extent.cache.LastAccessExtentCache; import com.sk89q.worldedit.extent.inventory.BlockBagExtent; import com.sk89q.worldedit.extent.reorder.MultiStageReorder; @@ -31,6 +32,7 @@ import com.sk89q.worldedit.extent.world.BlockQuirkExtent; import com.sk89q.worldedit.extent.world.ChunkLoadingExtent; import com.sk89q.worldedit.extent.world.FastModeExtent; import com.sk89q.worldedit.extent.world.SurvivalModeExtent; +import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.util.eventbus.EventHandler.Priority; import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.world.World; @@ -41,9 +43,6 @@ public class WESubscriber { public void onEditSession(EditSessionEvent event) { World worldObj = event.getWorld(); String world = worldObj.getName(); - if (!PS.get().isPlotWorld(world)) { - return; - } Actor actor = event.getActor(); if (actor != null && actor.isPlayer()) { String name = actor.getName(); @@ -58,16 +57,21 @@ public class WESubscriber { if (Permissions.hasPermission(player, "plots.worldedit.bypass")) { MainUtil.sendMessage(player, C.WORLDEDIT_BYPASS); } - event.setExtent(new NullExtent()); + if (PS.get().isPlotWorld(world)) { + event.setExtent(new NullExtent()); + } return; } if (Settings.CHUNK_PROCESSOR) { if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) { try { + LocalSession session = ((BukkitMain) PS.get().IMP).worldEdit.getWorldEdit().getSession(name); + boolean hasMask = session.getMask() != null; AbstractDelegateExtent extent = (AbstractDelegateExtent) event.getExtent(); ChangeSetExtent history = null; MultiStageReorder reorder = null; - boolean fast = ((BukkitMain) PS.get().IMP).worldEdit.getWorldEdit().getSession(name).hasFastMode(); + MaskingExtent maskextent = null; + boolean fast = session.hasFastMode(); while (extent.getExtent() != null && extent.getExtent() instanceof AbstractDelegateExtent) { AbstractDelegateExtent tmp = (AbstractDelegateExtent) extent.getExtent(); if (tmp.getExtent() != null && tmp.getExtent() instanceof AbstractDelegateExtent) { @@ -77,6 +81,9 @@ public class WESubscriber { if (tmp instanceof MultiStageReorder) { reorder = (MultiStageReorder) tmp; } + if (hasMask && tmp instanceof MaskingExtent) { + maskextent = tmp; + } extent = tmp; } else { @@ -96,8 +103,15 @@ public class WESubscriber { event.setExtent(new ExtentWrapper(extent)); } else { - ExtentWrapper wrapper = new ExtentWrapper(history); - event.setExtent(wrapper); + if (maskextent != null) { + ExtentWrapper wrapper = new ExtentWrapper(maskextent); + field.set(maskextent, history); + event.setExtent(wrapper); + } + else { + ExtentWrapper wrapper = new ExtentWrapper(history); + event.setExtent(wrapper); + } field.set(history, reorder); field.set(reorder, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper)); } @@ -108,9 +122,11 @@ public class WESubscriber { e.printStackTrace(); } } - event.setExtent(new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(), event.getExtent())); + if (PS.get().isPlotWorld(world)) { + event.setExtent(new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(), event.getExtent())); + } } - else { + else if (PS.get().isPlotWorld(world)) { event.setExtent(new WEExtent(mask, event.getExtent())); } }