How would I check which slot the item was dropped from?

Discussion in 'Plugin Development' started by XXLuigiMario, Jan 5, 2016.

Thread Status:
Not open for further replies.
  1. Hello, I'm trying to check whether the player has dropped his item in hand in the PlayerDropItemEvent but it turns out that once that event is called the player's item in hand is has been already set to air, so I can't simply do:
    player.getItemInHand().equals(event.getItemDrop().getItemStack())

    Instead is there a way to know which slot the item was dropped from to check it like this:
    player.getInventory().getHeldItemSlot() == droppedItemSlot

    Thanks for your time.
     
  2. Offline

    mine-care

    Not sure i understood, ill give it a go tho.
    So, if you call this:
    from the ItemDropEvent, it will give you the slot of the item the player had in hand when they droped it. BUT be careful, if i open my inventory and drag an item out of it, it will still fire. In that case it is not going to work since the item that was droped can be anything.

    Sorry if i wasnt helpful. :(
     
  3. Offline

    Ruptur

    @XXLuigiMario
    What are you trying to do, perhaps there is an easier way of doing it
     
  4. @Ruptur I'm trying to keep track of the held item so I can apply effects to the player while he holds it... I have done this in the past with BukkitTasks but I wanted to try to handle it with events this time since I thought it might be more efficient.

    That's why I asked this question, I want to make sure it's the held item and only the held item.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  5. Offline

    MisterErwin

    @XXLuigiMario PlayerInventory#getHeldItemSlot()

    That function returns the currently selected slot (0-8). To get the Inventory use Player#getInventory()

    And the only other way to fire that event, is if you throw it out of your inventory.

    (InventoryActionEvent and Type: DROP)

    If you combine these two, you get the slot.
     
Thread Status:
Not open for further replies.

Share This Page