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.
This commit is contained in:
wizjany 2019-04-06 14:24:01 -04:00
parent 397a71a602
commit 453740b56a
2 changed files with 9 additions and 13 deletions

View File

@ -59,7 +59,9 @@
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.block.DoubleChest; import org.bukkit.block.DoubleChest;
import org.bukkit.block.Dropper;
import org.bukkit.block.Hopper; import org.bukkit.block.Hopper;
import org.bukkit.block.PistonMoveReaction; import org.bukkit.block.PistonMoveReaction;
import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.AreaEffectCloud;
@ -861,8 +863,9 @@ public void onInventoryMoveItem(InventoryMoveItemEvent event) {
InventoryHolder sourceHolder = event.getSource().getHolder(); InventoryHolder sourceHolder = event.getSource().getHolder();
InventoryHolder targetHolder = event.getDestination().getHolder(); InventoryHolder targetHolder = event.getDestination().getHolder();
if (causeHolder instanceof Hopper if ((causeHolder instanceof Hopper || causeHolder instanceof Dropper)
&& ((BukkitWorldConfiguration) WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(BukkitAdapter.adapt(((Hopper) causeHolder).getWorld()))).ignoreHopperMoveEvents) { && ((BukkitWorldConfiguration) WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(
BukkitAdapter.adapt(((Container) causeHolder).getWorld()))).ignoreHopperMoveEvents) {
return; return;
} }
@ -879,19 +882,15 @@ public void onInventoryMoveItem(InventoryMoveItemEvent event) {
cause = Cause.unknown(); cause = Cause.unknown();
} }
if (!causeHolder.equals(sourceHolder)) { if (causeHolder != null && !causeHolder.equals(sourceHolder)) {
handleInventoryHolderUse(event, cause, sourceHolder); handleInventoryHolderUse(event, cause, sourceHolder);
} }
handleInventoryHolderUse(event, cause, targetHolder); handleInventoryHolderUse(event, cause, targetHolder);
if (event.isCancelled() && causeHolder instanceof Hopper) { if (event.isCancelled() && causeHolder instanceof Hopper) {
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(),
@Override () -> ((Hopper) causeHolder).getBlock().breakNaturally());
public void run() {
((Hopper) causeHolder).getBlock().breakNaturally();
}
});
} else { } else {
entry.setCancelled(event.isCancelled()); entry.setCancelled(event.isCancelled());
} }

View File

@ -136,10 +136,7 @@ static void formatAndSendDenyMessage(String what, LocalPlayer localPlayer, Strin
private boolean isWhitelisted(Cause cause, World world, boolean pvp) { private boolean isWhitelisted(Cause cause, World world, boolean pvp) {
Object rootCause = cause.getRootCause(); Object rootCause = cause.getRootCause();
if (rootCause instanceof Block) { if (rootCause instanceof Player) {
Material type = ((Block) rootCause).getType();
return type == Material.HOPPER || type == Material.DROPPER;
} else if (rootCause instanceof Player) {
Player player = (Player) rootCause; Player player = (Player) rootCause;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
WorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(world)); WorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(world));