Cancelling item dropping

Discussion in 'Plugin Development' started by Limeth, Nov 18, 2012.

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

    ever_x

    I know this thread is old, but for people who want to know a fully working method, I use this:
    Code:java
    1.  
    2. Player p = e.getPlayer();
    3. ItemStack item = e.getItemDrop().getItemStack().clone();
    4. item.setAmount(p.getInventory().getItemInHand().getAmount() + 1);
    5. e.getItemDrop().remove();
    6. p.getInventory().setItem(p.getInventory().getHeldItemSlot(), item);
    7.  

    Use this inside a PlayerDropItemEvent obviously! This is an amendment of the code above, but the amount + 1 bit will keep the proper size of the ItemStack.
     
    NathanWolf and joserobjr like this.
  2. Offline

    NathanWolf

    Sorry to semi-necrobump this thread, but it was really useful to me. It's kind of crazy that this bug hasn't been fixed yet.

    At any rate the solution provided here works great, except that you can open your inventory and hit Q on an item that's not in your hand. If you want to prevent dropping that item, the above solution breaks since it assumes it needs to put the item back in the active slot.

    Since the event doesn't tell us which item slot was dropped, I don't currently see a solution for this... I'm open to ideas! :)

    EDIT: Answered my own question, you can cancel the inventory click event in that special case. Sorry for the necrobump!
     
Thread Status:
Not open for further replies.

Share This Page