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


    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
    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.sendMessage("§a§lEvent Fired");
    With no luck. It is saying that
            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

  2. Offline


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


    TheWolfBadger likes this.
  4. Offline


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

Share This Page