I have some problems wifh the InventoryCloseEvent. How i can make that wen peopel close a chest the chest set 0 and drop a chest ?? THX
I'd say make a player interact event to store the location of the last opened chest that was right-clicked, then on inventory close if (event.getInventory().getType() == InventoryType.CHEST) set the Material of the block on the location of the last opened chest to air. For dropping it, i dont know myself, i'd guess it has something to do with spawn entity.
MrEpic All inventories should have owners; simply use inv.getHolder(), cast it to a chest state, (different from Material.CHEST) and get the block from that. Edit: It should end up looking something like this; Code:java ((Chest) inv.getHolder()).getBlock().breakNaturally();
My code is Code:java @EventHandler public void onInventoryCloseEvent(InventoryCloseEvent e){ Inventory inv = e.getInventory(); InventoryHolder holder = inv.getHolder(); if(holder != null && holder instanceof Chest){ Chest chest = (Chest) holder; Block block = chest.getBlock(); if (block.getType() == Material.TRAPPED_CHEST); block.setType(Material.AIR); But the chest should only set Air when the chest is emty
Code:java @EventHandlerpublic void onInventoryCloseEvent(InventoryCloseEvent e){Inventory inv = e.getInventory();InventoryHolder holder = inv.getHolder(); if(holder != null && holder instanceof Chest){Chest chest = (Chest) holder;Block block = chest.getBlock(); if (block.getType() == Material.TRAPPED_CHEST); if (block.isEmpty()){block.setType(Material.AIR);}}} please correct me if im wrong