From a5dbcccb59bf5810115fd1e0e3f00660c2a05fa8 Mon Sep 17 00:00:00 2001 From: Emilia Kond Date: Sat, 10 Feb 2024 08:49:41 +0200 Subject: [PATCH] Don't allow droppers to move items if redstone is disallowed A follow-up to #110. Droppers don't always call BlockDispenseEvent. If they're facing another inventory, they will instead call InventoryItemMoveEvent. --- .../org/popcraft/bolt/listeners/InventoryListener.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bukkit/src/main/java/org/popcraft/bolt/listeners/InventoryListener.java b/bukkit/src/main/java/org/popcraft/bolt/listeners/InventoryListener.java index a0f9a054..460089d2 100644 --- a/bukkit/src/main/java/org/popcraft/bolt/listeners/InventoryListener.java +++ b/bukkit/src/main/java/org/popcraft/bolt/listeners/InventoryListener.java @@ -36,6 +36,7 @@ public final class InventoryListener implements Listener { private static final SourceResolver BLOCK_SOURCE_RESOLVER = new SourceTypeResolver(Source.of(SourceTypes.BLOCK)); + private static final SourceResolver REDSTONE_SOURCE_RESOLVER = new SourceTypeResolver(Source.of(SourceTypes.REDSTONE)); private static final InventoryType CRAFTER_TYPE = EnumUtil.valueOf(InventoryType.class, "CRAFTER").orElse(null); private static final Material CRAFTER_MATERIAL = EnumUtil.valueOf(Material.class, "CRAFTER").orElse(null); private static final Map> INVENTORY_TYPE_BLOCKS = new HashMap<>(Map.of( @@ -153,6 +154,13 @@ public void onInventoryMoveItem(final InventoryMoveItemEvent e) { if (sourceProtection == null && destinationProtection == null) { return; } + // Droppers can move items to another container, but they need to be activated by redstone to do so + if (sourceProtection != null && InventoryType.DROPPER.equals(e.getSource().getType())) { + if (!plugin.canAccess(sourceProtection, REDSTONE_SOURCE_RESOLVER, Permission.REDSTONE)) { + e.setCancelled(true); + return; + } + } if (sourceProtection != null && destinationProtection != null) { if (!plugin.canAccess(destinationProtection, sourceProtection.getOwner(), Permission.DEPOSIT) || !plugin.canAccess(sourceProtection, destinationProtection.getOwner(), Permission.WITHDRAW)) { e.setCancelled(true);