PlayerPickupItemEvent event.getPlayer().getItemInHand() problem

Discussion in 'Plugin Development' started by 94jp, Dec 28, 2013.

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

    94jp

    Code:java
    1. // TODO FIX THIS. THIS ISN'T WORKING ATM....
    2. @EventHandler
    3. public void onPlayerPickupItem(PlayerPickupItemEvent event) {
    4. Player player = event.getPlayer();
    5. /*
    6.   * TODO getItemInHand() returns item held before player picks the item
    7.   * up. For example, let's say I have nothing on hand, then I pick up a
    8.   * sword. I now have a sword in hand, but getItemInhand() will return
    9.   * Air. I want it to return sword.
    10.   */
    11. if (player.getItemInHand().getItemMeta() != null
    12. || player.getItemInHand() != null) { ....


    Any help?
     
  2. Offline

    zack6849

    Because the event is fired before the iteminhand is set to the sword, i would schedule a task a few seconds later
     
  3. Offline

    WinX64

    Use event.getItem().getItemStack() instead.
     
    94jp likes this.
Thread Status:
Not open for further replies.

Share This Page