Solved Is Chest a double chest

Discussion in 'Spigot Help' started by C.roe, Jun 29, 2016.

  1. I wanted to know how I can tell if a chest is a douple chest
    Code (Text):
    @EventHandler
        public void onPlayerClick(PlayerInteractEvent e) {
            if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getClickedBlock().getState() instanceof Chest) {
                    Chest chest = (Chest) e.getClickedBlock();
                    if("chest is doublechest"){
                      //code goes here
                    }
                }
            }
        }
     
    • Useful Useful x 1
  2. So essentially you get the chest. get the inventory holder. check if that is instance of double chest. This code if from one of my plugins checking next to a signs location. Finding if it is a chest.

    So you would want
    Code (Text):
     Chest chest = (Chest) e.getClickedBlock();
    InventoryHolder ih = chest.getInventory().getHolder();
    if (ih instanceof DoubleChest) {
            //code
    }
     
    #2 L2_Envy, Jun 29, 2016
    Last edited: Jun 29, 2016
  3. kottalizer

    Supporter

    I'm sorry, but what are you doing?

    Get the inventory from the chest and look at the type of the inventory's holder ("instanceof").
     
  4. Yeah I didn't really give an explination
     
  5. kottalizer

    Supporter

    My question was a rhetorical way of implying `your code isn't even remotely efficient'.
     
  6. Thank you for your answerser.