Double Chest code?

Discussion in 'Plugin Development' started by wizzinangel, Sep 3, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    wizzinangel

    How would i check a double chest to see if it has a sign attached to it?

    I can do a single chest through the BlockFace, but not sure about double chests.

    Cheers
     
  2. Offline

    St3venAU

    I'm not sure if it's the most efficient way, but here's how I would do it. (Untested)
    Code:java
    1. Sign getSignOnAnyChest(Block chest) {
    2. BlockFace[] faces = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
    3. Sign sign = getSignOnSingleChest(chest);
    4. if(sign != null) {
    5. return sign;
    6. }
    7. for(BlockFace face : faces) {
    8. if(chest.getRelative(face).getType() == Material.CHEST) {
    9. return getSignOnSingleChest(chest.getRelative(face));
    10. }
    11. }
    12. return null;
    13. }
    14.  
    15. Sign getSignOnSingleChest(Block chest) {
    16. BlockFace[] faces = new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
    17. for(BlockFace face : faces) {
    18. if(chest.getRelative(face).getType() == Material.WALL_SIGN) {
    19. return (Sign) chest.getRelative(face).getState();
    20. }
    21. }
    22. return null;
    23. }
     
  3. Offline

    ColonelHedgehog

    Wouldn't checking the inventory size of a chest be a much easier way of doing this?
     
  4. Offline

    St3venAU

    ColonelHedgehog
    That might tell you if it is a double chest or not, but you would still have to search the 4 blocks around it to find where the other half of the chest is and then search around that chest for signs.
     
  5. Offline

    fireblast709

  6. Offline

    St3venAU

    fireblast709
    Are you sure it gives you the location of the other block? Sure, you can get the inventory, but I don't see anywhere in that documentation that would allow you to get the location of the other side of the chest.
     
  7. Offline

    fireblast709

    St3venAU you can get the InventoryHolders, which are org.bukkit.block.Chest. Do note that there are a bunch of instanceof checks in between :p
     
  8. Offline

    St3venAU

Thread Status:
Not open for further replies.

Share This Page