I was first using only getTitle()
for this but then found you need to use getView()
as well. So i did but I stil can't get it to work.
FYI This is the error :
Cannot resolve method 'getView' in 'Inventory'
I tried changing getInventory()
for InventoryView()
but still the same error but also the Cannot resolve method 'InventoryView' in 'Chest'
error so this means I cant get the inventory view from a block?
@EventHandler
public void onInteract(PlayerInteractEvent e) {
Action a = e.getAction();
Player p = e.getPlayer();
ItemStack hand = e.getItem();
Block clicked = e.getClickedBlock();
if (a != Action.PHYSICAL) {
assert clicked != null;
if(clicked.getType() == Material.CHEST){
hand.getType();
Chest chest = (Chest) clicked.getState();
Inventory inv = chest.getInventory();
if(inv.getView().getTitle().equalsIgnoreCase("Test")) {
p.sendMessage("Event triggered");
e.setCancelled(true);
}
}
}
}