How do I check what slot a player is clicking in(hotbar slots)

Discussion in 'Plugin Development' started by grasshopperMatt123, Mar 9, 2014.

Thread Status:
Not open for further replies.
  1. Hello, not sure if I should post this on BukkitDev but I have a question(Sort of obvious due to the title) and I would like if someone could post a brief example of how to do it. Thank you -Matt

    I am looking for ways to check if a player clicks in a specific slot.
     
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

  3. Offline

    Aqua

    grasshopperMatt123 likes this.
  4. Offline

    GameplayJDK

    grasshopperMatt123
    Listen to the PlayerInteractEvent and check if the player performed a rightclick. Google is your friend :)
    And then:
    Code:java
    1. Player p = event.getPlayer();
    2. if (p.getInventory().getHeldItemSlot() == <0 to 8>) {
    3. // do stuff
    4. }
     
    grasshopperMatt123 likes this.
  5. Thanks for all the help guys, really appreciate the bukkit community for all the help.

    Thanks, I couldn't access the Plugin sub-forum before.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  6. Offline

    GameplayJDK

  7. There is no held item, the item is just the slot, should it still get the slot of the held item? Thanks. -Matt
     
  8. Offline

    GameplayJDK

    grasshopperMatt123
    What exactly do you want to check?
    If you'd like to know if the player clicked with slot 3 selected you'd use p.getInventory().getHeldItemSlot() // which should be 2 if the 3rd slot was selected.
    If you want to get the itemstack, that is selected you will need to use p.getItemInHand() // which should return the itemstack that is being hold at the moment.

    Doc: http://jd.bukkit.org/rb/apidocs/org/bukkit/inventory/PlayerInventory.html
     
Thread Status:
Not open for further replies.

Share This Page