Inventory problem

Discussion in 'Plugin Development' started by Pik0, Jul 15, 2014.

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

    Pik0

    I am trying to prevent people from opening a inventory, hold and item and close the inventory. This would cause, normally in a item drop in the ground. However i use a item drop event:
    Code:java
    1. @EventHandler
    2. public void onDrop(PlayerDropItemEvent e) {
    3. Player dm = e.getPlayer();
    4. User dmg = Main.arenaManager.getUser(dm);
    5. if (dmg != null) {
    6. Player p = e.getPlayer();
    7. ItemStack item = e.getItemDrop().getItemStack().clone();
    8. item.setAmount(p.getInventory().getItemInHand().getAmount() + 1);
    9. e.getItemDrop().remove();
    10. p.getInventory().setItem(p.getInventory().getHeldItemSlot(), item);
    11. dm.updateInventory();
    12. }
    13. }

    Dont tell me "cancel the event". If i cancel and i drop the item in slot nÂș8, it will cancel but put the item in the first slot available.
    If i use this code and i hold an item in the inventory and close it, the inventory disappears and goes really buggy, and when it "updates" the item completly disappears.
    I tried to see the close event but i couldnt really see a solution :/

    I want to give the item back when this occurs

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

Share This Page