From 453740b56ad5e3753f8bc45446b2519e981322a7 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sat, 6 Apr 2019 14:24:01 -0400 Subject: [PATCH] Don't whitelist droppers and hoppers. By the time this code is called, the performance hit happened already. There's a separate way to whitelist these that still allows keeping the protections active. --- .../listener/EventAbstractionListener.java | 17 ++++++++--------- .../listener/RegionProtectionListener.java | 5 +---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 6b59bbdf..a86ca822 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -59,7 +59,9 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Chest; +import org.bukkit.block.Container; import org.bukkit.block.DoubleChest; +import org.bukkit.block.Dropper; import org.bukkit.block.Hopper; import org.bukkit.block.PistonMoveReaction; import org.bukkit.entity.AreaEffectCloud; @@ -861,8 +863,9 @@ public void onInventoryMoveItem(InventoryMoveItemEvent event) { InventoryHolder sourceHolder = event.getSource().getHolder(); InventoryHolder targetHolder = event.getDestination().getHolder(); - if (causeHolder instanceof Hopper - && ((BukkitWorldConfiguration) WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(((Hopper) causeHolder).getWorld()))).ignoreHopperMoveEvents) { + if ((causeHolder instanceof Hopper || causeHolder instanceof Dropper) + && ((BukkitWorldConfiguration) WorldGuard.getInstance().getPlatform().getGlobalStateManager().get( + BukkitAdapter.adapt(((Container) causeHolder).getWorld()))).ignoreHopperMoveEvents) { return; } @@ -879,19 +882,15 @@ public void onInventoryMoveItem(InventoryMoveItemEvent event) { cause = Cause.unknown(); } - if (!causeHolder.equals(sourceHolder)) { + if (causeHolder != null && !causeHolder.equals(sourceHolder)) { handleInventoryHolderUse(event, cause, sourceHolder); } handleInventoryHolderUse(event, cause, targetHolder); if (event.isCancelled() && causeHolder instanceof Hopper) { - Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() { - @Override - public void run() { - ((Hopper) causeHolder).getBlock().breakNaturally(); - } - }); + Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), + () -> ((Hopper) causeHolder).getBlock().breakNaturally()); } else { entry.setCancelled(event.isCancelled()); } diff --git a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java index d3a7d7cb..b846d039 100644 --- a/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java +++ b/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java @@ -136,10 +136,7 @@ static void formatAndSendDenyMessage(String what, LocalPlayer localPlayer, Strin private boolean isWhitelisted(Cause cause, World world, boolean pvp) { Object rootCause = cause.getRootCause(); - if (rootCause instanceof Block) { - Material type = ((Block) rootCause).getType(); - return type == Material.HOPPER || type == Material.DROPPER; - } else if (rootCause instanceof Player) { + if (rootCause instanceof Player) { Player player = (Player) rootCause; LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); WorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(world));