InventoryCloseEvent

Discussion in 'Plugin Development' started by MrEpic, Apr 2, 2014.

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

    MrEpic

    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
     
  2. 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.
     
    creepers84 likes this.
  3. Offline

    creepers84

    Dropping the item is simple, delete the item and just use .dropitemnaturally.
     
  4. Offline

    Maurdekye

    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
    1. ((Chest) inv.getHolder()).getBlock().breakNaturally();
     
    creepers84 likes this.
  5. Offline

    MrEpic

    My code is
    Code:java
    1. @EventHandler
    2. public void onInventoryCloseEvent(InventoryCloseEvent e){
    3. Inventory inv = e.getInventory();
    4. InventoryHolder holder = inv.getHolder();
    5.  
    6. if(holder != null && holder instanceof Chest){
    7. Chest chest = (Chest) holder;
    8. Block block = chest.getBlock();
    9.  
    10. if (block.getType() == Material.TRAPPED_CHEST);
    11.  
    12.  
    13. block.setType(Material.AIR);

    But the chest should only set Air when the chest is emty
     
  6. Offline

    Norbu10

    Code:java
    1. @EventHandler
    2. public void onInventoryCloseEvent(InventoryCloseEvent e){
    3. Inventory inv = e.getInventory();
    4. InventoryHolder holder = inv.getHolder();
    5.  
    6. if(holder != null && holder instanceof Chest){
    7. Chest chest = (Chest) holder;
    8. Block block = chest.getBlock();
    9.  
    10. if (block.getType() == Material.TRAPPED_CHEST);
    11.  
    12. if (block.isEmpty()){
    13. block.setType(Material.AIR);
    14. }
    15. }
    16. }

    please correct me if im wrong
     
  7. Offline

    MrEpic

    Thank you but its didnt work :(
     
  8. Offline

    MrEpic

    Push
     
Thread Status:
Not open for further replies.

Share This Page