Get the Chest from the InventoryCloseEvent

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

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


    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,
  2. Offline


    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. Offline


    I tried that, but it throws a ClassCastException, so...
  4. Offline


    I still haven't found the answer, if anyone of you guys knows please:)
    greetz blackwolf12333
  5. Offline


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

    @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