From 1fdc32e230c59581371d06fb7684e38dac5912b8 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Fri, 10 Aug 2012 18:59:10 +0200 Subject: [PATCH] uBlock now contains the chest neighbor methods --- com/Acrobot/ChestShop/Utils/uBlock.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/com/Acrobot/ChestShop/Utils/uBlock.java b/com/Acrobot/ChestShop/Utils/uBlock.java index d578e20..2734875 100644 --- a/com/Acrobot/ChestShop/Utils/uBlock.java +++ b/com/Acrobot/ChestShop/Utils/uBlock.java @@ -15,6 +15,31 @@ import org.bukkit.material.Attachable; public class uBlock { private static final BlockFace[] CHEST_EXTENSION_FACES = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH}; private static final BlockFace[] SHOP_FACES = {BlockFace.SELF, BlockFace.DOWN, BlockFace.UP, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH}; + private static final BlockFace[] NEIGHBOR_FACES = new BlockFace[]{BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH}; + + public static Sign getConnectedSign(Chest chest) { + Sign sign = uBlock.findAnyNearbyShopSign(chest.getBlock()); + + if (sign == null && getNeighbor(chest) != null) { + sign = uBlock.findAnyNearbyShopSign(getNeighbor(chest).getBlock()); + } + + return sign; + } + + private static Chest getNeighbor(Chest chest) { + Block chestBlock = chest.getBlock(); + + for (BlockFace chestFace : NEIGHBOR_FACES) { + Block relative = chestBlock.getRelative(chestFace); + + if (relative.getState() instanceof Chest) { + return (Chest) relative.getState(); + } + } + + return null; + } public static Chest findConnectedChest(Sign sign) { Block block = sign.getBlock();