Removing Items From A Closing Inventory

Discussion in 'Plugin Development' started by gandalfphysicist, Jun 13, 2014.

Thread Status:
Not open for further replies.
  1. Hello, I have reached a point in my plugin where it is required that I remove items from a closing inventory. The way I want to do this is by getting the contents of two specific slots of my custom inventory, removing them from the inventory, and dropping them at the player's location when the inventory closes. I have attempted to do this with the InventoryCloseEvent, but it does not seem to be working. Is there another way to do this?
     
  2. Offline

    Zwander

    Give us what you've got. That way we can try and find if the issue a programming logic issue, or if bukkit doesn't allow for it the way you are doing it.
     
    drtshock likes this.
  3. Gladly. The problem seems to be caused by the lack of ability to get the name, contents, etc. of a closing inventory.
    Code:java
    1. @EventHandler (priority = EventPriority.HIGHEST)
    2. public void onInventoryCloseEvent(InventoryCloseEvent event) {
    3.  
    4. Inventory inventory = event.getInventory();
    5. Player user = (Player) event.getPlayer();
    6. Location loc = user.getLocation();
    7. ItemStack emitter = inventory.getItem(13);
    8. ItemStack body = inventory.getItem(22);
    9.  
    10. if(inventory.getName().contains("Sonic Screwdriver Crafting")) {
    11. if(emitter != null) {
    12. user.getWorld().dropItemNaturally(loc, emitter);
    13. }
    14. if(body != null) {
    15. user.getWorld().dropItemNaturally(loc, body);
    16. }
    17. inventory.setItem(13, new ItemStack(Material.AIR));
    18. inventory.setItem(22, new ItemStack(Material.AIR));
    19. }
    20. }
    21. }
     
  4. Bump.

    I've just realized I haven't registered the event.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page