fix double chest protection - check both halves for shop signs
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user