From 0134b768a8296309a54938a5267a83b63dcbbba0 Mon Sep 17 00:00:00 2001 From: cybsec Date: Thu, 5 Feb 2026 18:41:25 -0500 Subject: [PATCH] fix double chest protection - check both halves for shop signs --- .../listener/ShopProtectionListener.java | 58 ++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/src/main/java/party/cybsec/oyeshops/listener/ShopProtectionListener.java b/src/main/java/party/cybsec/oyeshops/listener/ShopProtectionListener.java index dca7b65..0cbc80f 100644 --- a/src/main/java/party/cybsec/oyeshops/listener/ShopProtectionListener.java +++ b/src/main/java/party/cybsec/oyeshops/listener/ShopProtectionListener.java @@ -1,11 +1,16 @@ package party.cybsec.oyeshops.listener; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Chest; +import org.bukkit.block.DoubleChest; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.DoubleChestInventory; +import org.bukkit.inventory.Inventory; import party.cybsec.oyeshops.OyeShopsPlugin; import party.cybsec.oyeshops.model.Shop; import party.cybsec.oyeshops.permission.PermissionManager; @@ -49,7 +54,7 @@ public class ShopProtectionListener implements Listener { return; } - // find shop with this chest location + // find shop with this chest location (handles double chests) Shop chestShop = findShopByChest(block); if (chestShop != null) { if (canBreakShop(player, chestShop)) { @@ -88,17 +93,54 @@ public class ShopProtectionListener implements Listener { } /** - * find shop by chest location + * find shop by chest location (handles double chests) */ private Shop findShopByChest(Block chestBlock) { + // first check this block directly + Shop shop = findShopOnBlock(chestBlock); + if (shop != null) { + return shop; + } + + // if this is a chest, check the other half of a double chest + if (chestBlock.getState() instanceof Chest chest) { + Inventory inv = chest.getInventory(); + if (inv instanceof DoubleChestInventory doubleInv) { + DoubleChest doubleChest = doubleInv.getHolder(); + if (doubleChest != null) { + // check both sides + Chest left = (Chest) doubleChest.getLeftSide(); + Chest right = (Chest) doubleChest.getRightSide(); + + if (left != null) { + shop = findShopOnBlock(left.getBlock()); + if (shop != null) + return shop; + } + if (right != null) { + shop = findShopOnBlock(right.getBlock()); + if (shop != null) + return shop; + } + } + } + } + + return null; + } + + /** + * find shop sign attached to a specific block + */ + private Shop findShopOnBlock(Block containerBlock) { // check all adjacent blocks for wall signs - for (org.bukkit.block.BlockFace face : new org.bukkit.block.BlockFace[] { - org.bukkit.block.BlockFace.NORTH, - org.bukkit.block.BlockFace.SOUTH, - org.bukkit.block.BlockFace.EAST, - org.bukkit.block.BlockFace.WEST + for (BlockFace face : new BlockFace[] { + BlockFace.NORTH, + BlockFace.SOUTH, + BlockFace.EAST, + BlockFace.WEST }) { - Block adjacent = chestBlock.getRelative(face); + Block adjacent = containerBlock.getRelative(face); Shop shop = plugin.getShopRegistry().getShop(adjacent.getLocation()); if (shop != null) { return shop;