From 345b3440002233ae3130cba6079334d3929c8f4b Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 8 May 2018 15:24:50 +1000 Subject: [PATCH] Fix some region issues --- bukkit/src/main/resources/plugin.yml | 2 + .../com/boydti/fawe/util/ExtentTraverser.java | 4 +- .../java/com/boydti/fawe/util/WEManager.java | 55 +++++++++++-------- nukkit/src/main/resources/plugin.yml | 2 + 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 588e46c4..e6b0ecdc 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -18,6 +18,8 @@ permissions: fawe.plotsquared.trusted: true fawe.plotme: default: true + fawe.bypass.regions: + default: false fawe.bypass: default: false children: diff --git a/core/src/main/java/com/boydti/fawe/util/ExtentTraverser.java b/core/src/main/java/com/boydti/fawe/util/ExtentTraverser.java index 4b40f25e..64a0a6e3 100644 --- a/core/src/main/java/com/boydti/fawe/util/ExtentTraverser.java +++ b/core/src/main/java/com/boydti/fawe/util/ExtentTraverser.java @@ -60,7 +60,7 @@ public class ExtentTraverser { } public U findAndGet(Class clazz) { - ExtentTraverser traverser = find(clazz); + ExtentTraverser traverser = find((Class) clazz); return (traverser != null) ? (U) traverser.get() : null; } @@ -68,7 +68,7 @@ public class ExtentTraverser { try { ExtentTraverser value = this; while (value != null) { - if (clazz.isInstance(value.root)) { + if (clazz.isAssignableFrom(value.root.getClass())) { return (ExtentTraverser) value; } value = value.next(); 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 c18ca413..7a54591f 100644 --- a/core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -15,9 +15,8 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.regions.Region; import java.lang.reflect.Field; -import java.util.ArrayDeque; -import java.util.HashSet; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; public class WEManager { @@ -98,33 +97,37 @@ public class WEManager { } player.setMeta("lastMaskWorld", world); Set masks = player.getMeta("lastMask"); - HashSet regions = new HashSet<>(); + Set backupRegions = new HashSet<>(); + Set regions = new HashSet<>(); + + if (masks == null) { masks = new HashSet<>(); } else { - boolean removed = false; - if (masks.isEmpty()) { - removed = true; - } else { - for (FaweMask mask : masks) { - Region region = mask.getRegion(); - if (!region.contains(loc.x, loc.y, loc.z)) { - removed = true; + synchronized (masks) { + boolean removed = false; + if (!masks.isEmpty()) { + Iterator iter = masks.iterator(); + while (iter.hasNext()) { + FaweMask mask = iter.next(); + if (mask.isValid(player, type)) { + Region region = mask.getRegion(); + if (region.contains(loc.x, loc.y, loc.z)) { + regions.add(region); + } else { + removed = true; + backupRegions.add(region); + } + } else { + removed = true; + iter.remove(); + } } - if (!mask.isValid(player, type)) { - removed = true; - break; - } - regions.add(region); } - } - if (removed) { - masks.clear(); - regions.clear(); - } else { - return regions.toArray(new Region[regions.size()]); + if (!removed) return regions.toArray(new Region[regions.size()]); } } + Set tmpMasks = new HashSet<>(); for (final FaweMaskManager manager : managers) { if (player.hasPermission("fawe." + manager.getKey())) { try { @@ -138,6 +141,12 @@ public class WEManager { } } } + if (!tmpMasks.isEmpty()) { + masks = tmpMasks; + regions = masks.stream().map(mask -> mask.getRegion()).collect(Collectors.toSet()); + } else { + regions.addAll(backupRegions); + } if (!masks.isEmpty()) { player.setMeta("lastMask", masks); } else { diff --git a/nukkit/src/main/resources/plugin.yml b/nukkit/src/main/resources/plugin.yml index 46c76f43..a8b38f9b 100644 --- a/nukkit/src/main/resources/plugin.yml +++ b/nukkit/src/main/resources/plugin.yml @@ -10,6 +10,8 @@ permissions: fawe.plotsquared.trusted: true fawe.plotme: default: true + fawe.bypass.regions: + default: false fawe.bypass: default: false children: