From 4ac02d6297dd245f9dc8f60d79aae806f3f0abd8 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 23 May 2016 23:00:33 +1000 Subject: [PATCH] Fixes #121 --- .../bukkit/v0/BukkitEditSessionWrapper_0.java | 2 +- .../com/thevoxelbox/voxelsniper/Sniper.java | 2 +- .../fawe/bukkit/v1_8/BukkitMain_18.java | 3 +- .../fawe/bukkit/v1_9/BukkitMain_19.java | 3 +- .../main/java/com/boydti/fawe/FaweAPI.java | 2 +- .../main/java/com/boydti/fawe/config/BBC.java | 1 + .../com/boydti/fawe/object/FawePlayer.java | 2 +- .../fawe/object/extent/ProcessedWEExtent.java | 5 +- .../regions/general/PlotSquaredFeature.java | 7 ++- .../java/com/boydti/fawe/util/WEManager.java | 49 +++++++++---------- .../java/com/sk89q/worldedit/EditSession.java | 19 ++----- .../command/composition/SelectionCommand.java | 7 ++- 12 files changed, 47 insertions(+), 55 deletions(-) diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitEditSessionWrapper_0.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitEditSessionWrapper_0.java index 83a9a5a7..542239e2 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitEditSessionWrapper_0.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitEditSessionWrapper_0.java @@ -18,7 +18,7 @@ public class BukkitEditSessionWrapper_0 extends EditSessionWrapper { try { // Try to hook into BlocksHub this.hook = new BlocksHubHook(); - } catch (final Throwable e) {} + } catch (final Throwable ignore) {} } @Override diff --git a/bukkit0/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java b/bukkit0/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java index a147fc35..ca470481 100644 --- a/bukkit0/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java +++ b/bukkit0/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java @@ -113,7 +113,7 @@ public class Sniper { if (fp.getMeta("fawe_action") != null) { return false; } - RegionWrapper[] mask = WEManager.IMP.getMask(fp).toArray(new RegionWrapper[0]); + RegionWrapper[] mask = WEManager.IMP.getMask(fp); queue = FaweAPI.createQueue(fp.getLocation().world, true); this.mask = (MaskedFaweQueue) (queue = new MaskedFaweQueue(queue, mask)); com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld(); diff --git a/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitMain_18.java b/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitMain_18.java index efbf9a87..4759b2e5 100644 --- a/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitMain_18.java +++ b/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitMain_18.java @@ -1,6 +1,7 @@ package com.boydti.fawe.bukkit.v1_8; import com.boydti.fawe.bukkit.ABukkitMain; +import com.boydti.fawe.bukkit.v0.BukkitEditSessionWrapper_0; import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.object.EditSessionWrapper; import com.sk89q.worldedit.EditSession; @@ -14,6 +15,6 @@ public class BukkitMain_18 extends ABukkitMain { @Override public EditSessionWrapper getEditSessionWrapper(EditSession session) { - return new EditSessionWrapper(session); + return new BukkitEditSessionWrapper_0(session); } } diff --git a/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitMain_19.java b/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitMain_19.java index f1947e25..d9ef5315 100644 --- a/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitMain_19.java +++ b/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitMain_19.java @@ -1,6 +1,7 @@ package com.boydti.fawe.bukkit.v1_9; import com.boydti.fawe.bukkit.ABukkitMain; +import com.boydti.fawe.bukkit.v0.BukkitEditSessionWrapper_0; import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.object.EditSessionWrapper; import com.sk89q.worldedit.EditSession; @@ -13,6 +14,6 @@ public class BukkitMain_19 extends ABukkitMain { @Override public EditSessionWrapper getEditSessionWrapper(EditSession session) { - return new EditSessionWrapper(session); + return new BukkitEditSessionWrapper_0(session); } } diff --git a/core/src/main/java/com/boydti/fawe/FaweAPI.java b/core/src/main/java/com/boydti/fawe/FaweAPI.java index 1d128454..17f165bf 100644 --- a/core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -153,7 +153,7 @@ public class FaweAPI { * @param player * @return */ - public static Set getRegions(FawePlayer player) { + public static RegionWrapper[] getRegions(FawePlayer player) { return WEManager.IMP.getMask(player); } diff --git a/core/src/main/java/com/boydti/fawe/config/BBC.java b/core/src/main/java/com/boydti/fawe/config/BBC.java index cf7193c0..5c44eb19 100644 --- a/core/src/main/java/com/boydti/fawe/config/BBC.java +++ b/core/src/main/java/com/boydti/fawe/config/BBC.java @@ -118,6 +118,7 @@ public enum BBC { WORLDEDIT_CANCEL_REASON_MAX_ENTITIES("Too many entities", "Cancel"), WORLDEDIT_CANCEL_REASON_MAX_ITERATIONS("Max iterations", "Cancel"), WORLDEDIT_CANCEL_REASON_MAX_FAILS("Outside allowed region", "Cancel"), + WORLDEDIT_CANCEL_REASON_NO_REGION("No allowed region", "Cancel"), WORLDEDIT_FAILED_LOAD_CHUNK("&cSkipped loading chunk: &7%s0;%s1&c. Try increasing chunk-wait.", "Cancel"), LOADING_CLIPBOARD("Loading clipboard from disk, please wait.", "History"), diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index b45b4d6e..070e05fe 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -281,7 +281,7 @@ public abstract class FawePlayer { * Get the player's current allowed WorldEdit regions * @return */ - public HashSet getCurrentRegions() { + public RegionWrapper[] getCurrentRegions() { return WEManager.IMP.getMask(this); } diff --git a/core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java b/core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java index 5bd6d969..6aa0fac2 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java @@ -16,16 +16,15 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; -import java.util.HashSet; import java.util.List; public class ProcessedWEExtent extends FaweRegionExtent { private final FaweLimit limit; private final RegionWrapper[] mask; - public ProcessedWEExtent(final Extent parent, final HashSet mask, FaweLimit limit) { + public ProcessedWEExtent(final Extent parent, final RegionWrapper[] mask, FaweLimit limit) { super(parent); - this.mask = mask.toArray(new RegionWrapper[mask.size()]); + this.mask = mask; this.limit = limit; } diff --git a/core/src/main/java/com/boydti/fawe/regions/general/PlotSquaredFeature.java b/core/src/main/java/com/boydti/fawe/regions/general/PlotSquaredFeature.java index 156e6da5..4226446c 100644 --- a/core/src/main/java/com/boydti/fawe/regions/general/PlotSquaredFeature.java +++ b/core/src/main/java/com/boydti/fawe/regions/general/PlotSquaredFeature.java @@ -4,6 +4,7 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.FaweMaskManager; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RegionWrapper; import com.plotsquared.listener.WEManager; @@ -21,7 +22,11 @@ public class PlotSquaredFeature extends FaweMaskManager { public FaweMask getMask(FawePlayer fp) { final PlotPlayer pp = PlotPlayer.wrap((Player) fp.parent); final HashSet regions = WEManager.getMask(pp); - if (regions.size() == 0 || !PS.get().hasPlotArea(pp.getLocation().getWorld())) { + if (regions.size() == 0) { + Plot plot = pp.getCurrentPlot(); + if (plot.isOwner(pp.getUUID())) { + System.out.println("INVALID MASK? " + WEManager.getMask(pp) + " | " + plot + " | " + pp.getName()); + } return null; } final HashSet faweRegions = new HashSet<>(); 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 9f70be13..1004a06d 100644 --- a/core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -2,7 +2,6 @@ package com.boydti.fawe.util; import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; -import com.boydti.fawe.object.FaweLocation; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RunnableVal; @@ -64,47 +63,43 @@ public class WEManager { * @param player * @return */ - public HashSet getMask(final FawePlayer player) { - return TaskManager.IMP.sync(new RunnableVal>() { + public RegionWrapper[] getMask(final FawePlayer player) { + HashSet mask = TaskManager.IMP.sync(new RunnableVal>() { @Override - public void run(HashSet value) { - final HashSet regions = new HashSet<>(); + public void run(HashSet ignore) { + this.value = new HashSet<>(); + String world = player.getLocation().world; + if (!world.equals(player.getMeta("lastMaskWorld"))) { + player.deleteMeta("lastMaskWorld"); + player.deleteMeta("lastMask"); + } + player.setMeta("lastMaskWorld", world); if (player.hasPermission("fawe.bypass") || !Settings.REGION_RESTRICTIONS) { - regions.add(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE)); - player.deleteMeta("lastmask"); - this.value = regions; + value.add(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE)); return; } for (final FaweMaskManager manager : managers) { if (player.hasPermission("fawe." + manager.getKey())) { final FaweMask mask = manager.getMask(player); if (mask != null) { - regions.addAll(mask.getRegions()); + value.addAll(mask.getRegions()); } } } - if (regions.size() == 0) { - HashSet mask = player.>getMeta("lastmask"); - if (mask != null) { - FaweLocation loc = player.getLocation(); - for (RegionWrapper region : mask) { - if (region.isIn(loc.x, loc.z)) { - player.deleteMeta("lastmask"); - this.value = regions; - return; - } - } - this.value = mask; - return; - } - } - player.setMeta("lastmask", regions); - this.value = regions; - return; } }, 1000); + if (mask == null || mask.isEmpty()) { + mask = player.getMeta("lastMask"); + if (mask == null) { + mask = new HashSet<>(); + } + } + player.setMeta("lastmask", mask); + return mask.toArray(new RegionWrapper[mask.size()]); } + + public boolean intersects(final RegionWrapper region1, final RegionWrapper region2) { return (region1.minX <= region2.maxX) && (region1.maxX >= region2.minX) && (region1.minZ <= region2.maxZ) && (region1.maxZ >= region2.minZ); } diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index b09a1621..b9b1769f 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -261,7 +261,7 @@ public class EditSession implements Extent { } Extent extent; - HashSet mask; + RegionWrapper[] mask; final FawePlayer fp = FawePlayer.wrap(actor); final LocalSession session = fp.getSession(); this.fastmode = session.hasFastMode(); @@ -287,9 +287,9 @@ public class EditSession implements Extent { queue.addEditSession(this); this.limit = fp.getLimit(); mask = WEManager.IMP.getMask(fp); - if (mask.size() == 0) { + if (mask.length == 0) { // No allowed area; return null extent - extent = this.regionExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_MAX_FAILS); + extent = this.regionExtent = new NullExtent(world, BBC.WORLDEDIT_CANCEL_REASON_NO_REGION); this.bypassReorderHistory = extent; this.bypassHistory = extent; this.bypassNone = extent; @@ -426,23 +426,14 @@ public class EditSession implements Extent { eventBus.post(event); final Extent toReturn = event.getExtent(); if (toReturn != extent) { - String className = toReturn.getClass().getSimpleName().toLowerCase(); - if (className.contains("coreprotect")) { - if (Settings.EXTENT_DEBUG) { - Fawe.debug("&cUnsafe extent detected: " + toReturn.getClass().getCanonicalName() + " !"); - Fawe.debug("&8 - &7Use BlocksHub instead"); - Fawe.debug("&8 - &7Or use FAWE rollback"); - Fawe.debug("&8 - &7Change `extent.debug: false` to hide this message"); - } - return extent; - } + String className = toReturn.getClass().getName().toLowerCase(); for (String allowed : Settings.ALLOWED_3RDPARTY_EXTENTS) { if (className.contains(allowed.toLowerCase())) { return toReturn; } } if (Settings.EXTENT_DEBUG) { - Fawe.debug("&cPotentially inefficient WorldEdit extent: " + toReturn.getClass().getSimpleName()); + Fawe.debug("&cPotentially inefficient WorldEdit extent: " + toReturn.getClass().getName()); Fawe.debug("&8 - &7For area restrictions, it is recommended to use the FaweAPI"); Fawe.debug("&8 - &7To allow this plugin add it to the FAWE `allowed-plugins` list"); } diff --git a/core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java b/core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java index 0046e763..652a6eb4 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java +++ b/core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java @@ -22,10 +22,10 @@ package com.sk89q.worldedit.command.composition; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FawePlayer; +import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.NullChangeSet; import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RunnableVal; -import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.WEManager; import com.google.common.base.Joiner; @@ -55,7 +55,6 @@ import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.util.command.composition.CommandExecutor; import com.sk89q.worldedit.util.command.composition.SimpleCommand; import java.lang.reflect.Field; -import java.util.HashSet; import java.util.List; @@ -105,9 +104,9 @@ public class SelectionCommand extends SimpleCommand { RegionFunction function = ((RegionVisitor) operation).function; RegionWrapper current = new RegionWrapper(cuboid.getMinimumPoint(), cuboid.getMaximumPoint()); FawePlayer fp = FawePlayer.wrap(player); - HashSet mask = WEManager.IMP.getMask(fp); + RegionWrapper[] mask = WEManager.IMP.getMask(fp); - if (function instanceof BlockReplace && mask.size() == 1 && mask.iterator().next().contains(current)) { + if (function instanceof BlockReplace && mask.length == 1 && mask[0].equals(current)) { try { BlockReplace replace = ((BlockReplace) function); Field field = replace.getClass().getDeclaredField("pattern");