Solved Get Inventory Name of Placed Chest

Discussion in 'Plugin Development' started by glasseater, Nov 24, 2016.

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

    glasseater

    Hey guys,
    So basically what I am trying to accomplish today is getting the inventory name of a placed chest. I want it so when you right click the placed with the defined (inventory name) chest it runs a command.

    I tried this
    Code:
    @EventHandler
    public void onInteract(PlayerInteractEvent e) {
        Action a = e.getAction();
        Player p = e.getPlayer();
        ItemStack hand = e.getItem();
        Block clicked = (Block) e.getClickedBlock();
    
        if (a != Action.PHYSICAL) {
            if(clicked.getType() == Material.CHEST){
                  if (hand.getType() !=null) {
                  Chest chest = (Chest) clicked.getState();
                  Inventory inv = chest.getInventory();
                  if(inv.getTitle().equalsIgnoreCase("Crates")) {
                    p.performCommand("crate");
                    p.sendMessage("§a§lEvent Fired");
                    e.setCancelled(true);
                   
                }
    
               
            }
        }
    
    }
    }}
    With no luck. It is saying that
    Code:
            if(clicked.getType() == Material.CHEST){
    this is null, but I don't understand why this would be null in this case.
    If you have any idea please let me know! Thanks


    Glass
     
  2. Offline

    TheWolfBadger

    Put in an if statement before you check the type like this "if (clicked !=null)"
     
  3. Offline

    glasseater

    TheWolfBadger likes this.
  4. Offline

    Zombie_Striker

    @glasseater
    If your problem has been solved, mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page