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.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());
}

View File

@ -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));