From 594d72d2fe6f26af58dbba9afa29c16ca924e3c2 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 5 Sep 2018 07:09:24 +1000 Subject: [PATCH] Fix free build restrictions --- .../fawe/bukkit/regions/FreeBuildRegion.java | 48 +++++++++++-------- .../fawe/object/queue/NullFaweQueue.java | 17 ++++++- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java index 6ed5a6d38..130899b39 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java @@ -10,18 +10,17 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.world.block.BlockTypes; +import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.BlockState; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.EventException; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.RegisteredListener; import java.util.ArrayList; @@ -32,7 +31,7 @@ public class FreeBuildRegion extends BukkitMaskManager { public FreeBuildRegion() { super("freebuild"); this.listeners = new ArrayList<>(); - RegisteredListener[] listeners = BlockPlaceEvent.getHandlerList().getRegisteredListeners(); + RegisteredListener[] listeners = BlockBreakEvent.getHandlerList().getRegisteredListeners(); for (RegisteredListener listener : listeners) { if (listener.getPriority() == EventPriority.MONITOR) continue; if (!listener.isIgnoringCancelled()) continue; @@ -57,42 +56,51 @@ public class FreeBuildRegion extends BukkitMaskManager { if (currRegList.isEmpty()) return null; RegisteredListener[] listeners = currRegList.toArray(new RegisteredListener[currRegList.size()]); - World world = player.parent.getWorld(); - AsyncWorld asyncWorld = AsyncWorld.wrap(world); + World bukkitWorld = player.parent.getWorld(); + AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld); - Vector vec1 = asyncWorld.getMinimumPoint(); - Vector vec2 = asyncWorld.getMaximumPoint(); - Location pos1 = BukkitAdapter.adapt(world, vec1); - Location pos2 = BukkitAdapter.adapt(world, vec2); + Vector vec1 = new Vector(0, 0, 0); + Vector vec2 = vec1; + Location pos1 = BukkitAdapter.adapt(bukkitWorld, vec1); + Location pos2 = BukkitAdapter.adapt(bukkitWorld, vec2); - AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName()), 0, 0, 0); + AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName(), BlockTypes.STONE.getDefaultState()), 0, 0, 0); BlockBreakEvent event = new BlockBreakEvent(block, player.parent); - return new BukkitMask(pos1, pos2) { + @Override + public String getName() { + return "freebuild-global"; + } + + @Override + public boolean isValid(FawePlayer player, MaskType type) { + return bukkitWorld == ((FawePlayer)player).parent.getWorld() && type == MaskType.MEMBER; + } + @Override public Region getRegion() { return new CuboidRegion(vec1, vec2) { @Override - public boolean contains(int x, int y, int z) { - return contains(x, z); + public boolean contains(int x, int z) { + return contains(x, 77, z); } private int lastX = Integer.MIN_VALUE, lastZ = Integer.MIN_VALUE; private boolean lastResult; @Override - public boolean contains(int x, int z) { + public boolean contains(int x, int y, int z) { if (x == lastX && z == lastZ) return lastResult; lastX = x; lastZ = z; - int y = 128; event.setCancelled(false); block.setPosition(x, y, z); try { - for (RegisteredListener listener : listeners) { - listener.callEvent(event); - if (event.isCancelled()) break; + synchronized (Bukkit.getPluginManager()) { + for (RegisteredListener listener : listeners) { + listener.callEvent(event); + } } } catch (EventException e) { throw new RuntimeException(e); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java index febcca52c..41576b36e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java @@ -7,8 +7,10 @@ import com.boydti.fawe.object.RunnableVal2; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.SetQueue; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import java.io.File; @@ -19,9 +21,15 @@ import javax.annotation.Nullable; public class NullFaweQueue implements FaweQueue { private final String worldName; + private final BlockState state; public NullFaweQueue(String worldName) { + this(worldName, BlockTypes.AIR.getDefaultState()); + } + + public NullFaweQueue(String worldName, BlockState state) { this.worldName = worldName; + this.state = state; } @Override @@ -179,14 +187,19 @@ public class NullFaweQueue implements FaweQueue { return 0; } + @Override + public BlockState getBlock(Vector position) { + return state; + } + @Override public int getCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException { - return BlockTypes.AIR.getInternalId(); + return state.getInternalId(); } @Override public int getCachedCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException { - return BlockTypes.AIR.getInternalId(); + return state.getInternalId(); } @Override