From 04193eef048296cca1f2e8298b38e93dcb710e55 Mon Sep 17 00:00:00 2001 From: Relluem94 Date: Sat, 20 Apr 2024 17:24:40 +0200 Subject: [PATCH] RE-186 Fixed Double Chest Protection Ignored from Hoppers (getLocation gives not back Block XYZ) --- .../spigot/essentials/events/BetterLock.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java index aff9635a..0e9b567e 100644 --- a/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java +++ b/src/main/java/de/relluem94/minecraft/server/spigot/essentials/events/BetterLock.java @@ -111,6 +111,7 @@ public void onWaterMove(BlockFromToEvent e) { private boolean handleMoveItemEvent(Inventory inventory, ItemStack is, boolean isSource) { Location location; + Location locationOtherSide = null; InventoryHolder holder; if(inventory != null){ holder = inventory.getHolder(); @@ -122,18 +123,37 @@ private boolean handleMoveItemEvent(Inventory inventory, ItemStack is, boolean i try { if (holder instanceof BlockState) { location = ((BlockState)holder).getLocation(); - } else if (holder instanceof DoubleChest) { - location = ((DoubleChest)holder).getLocation(); + } else if (holder instanceof DoubleChest doubleChest) { + location = Objects.requireNonNull(doubleChest.getRightSide()).getInventory().getLocation().getBlock().getLocation(); + locationOtherSide = Objects.requireNonNull(doubleChest.getLeftSide()).getInventory().getLocation().getBlock().getLocation(); } else { return false; } } catch (Exception e) { return false; - } + } ProtectionEntry protection = RelluEssentials.getInstance().getProtectionAPI().getProtectionEntry(location); + if (protection == null){ - return false; + if(locationOtherSide == null){ + return false; + } + else{ + protection = RelluEssentials.getInstance().getProtectionAPI().getProtectionEntry(locationOtherSide); + } + + if (protection == null){ + return false; + } + else{ + if(isSource){ + return !ProtectionHelper.hasFlag(protection, ProtectionFlags.ALLOW_HOPPER); + } + else{ + return true; + } + } } else{ return !ProtectionHelper.hasFlag(protection, ProtectionFlags.ALLOW_HOPPER);