Get the Chest from the InventoryCloseEvent

Discussion in 'Plugin Development' started by blackwolf12333, Jun 20, 2012.

Thread Status:
Not open for further replies.
  1. Hi guys, i have a question, i need to get the Chest block from the inventory when it is closed, i need that to log its location in the world, I tried casting it, but that doesn't work...

    thanks in advance,
    blackwolf123333
     
  2. You probably want to check if the holder of the inventory is an instance of a chest and then cast it. Then you have the possibility to get the block from that chest.
     
  3. I tried that, but it throws a ClassCastException, so...
     
  4. I still haven't found the answer, if anyone of you guys knows please:)
    greetz blackwolf12333
     
  5. Offline

    eccentric_nz

    Found myself wanting to do the same thing, your thread is top of google's results for bukkit get chest inventoryCloseEvent...

    Code:
    @EventHandler(priority = EventPriority.NORMAL)
        public void onChestClose(InventoryCloseEvent event) {
            Inventory inv = event.getInventory();
            InventoryHolder holder = inv.getHolder();
            if (holder instanceof Chest) {
                Chest chest = (Chest) holder;
                Location loc = chest.getLocation();
                Player player = (Player) event.getPlayer();
                player.sendMessage("You closed the chest!");
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page