Solved Can't destroy item with Player.setItemInHand(null)

Discussion in 'Plugin Development' started by Cin316, Jul 24, 2013.

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

    Cin316

    I am making a Bukkit plugin, and in my plugin I need to destroy a user's held item. I am trying to use the method of
    Code:java
    1. Player.getInventory().setItemInHand(null);
    to remove the item. It works in one of my classes (RobbersBladeListener), but not in another (SimoonsDealListener). I have no idea why this is happening. I've tried
    Code:java
    1. Player.setItemInHand(null);
    and
    Code:java
    1. Player.getItemInHand.setAmount(0);
    but none of them work in the SimoonsDealListener class.

    Does anyone else have this problem? Can someone tell me why this is happening?

    Full source code is at http://www.github.com/cin316/minez-legendary-weapons/
     
  2. Offline

    Assist

    Cin316
    How about you use getInventory inbetween Player and setItemInHand(), just like you did in RobbersBladeListener?
     
  3. Offline

    Cin316

    I have, and it still doesn't work.
     
  4. Offline

    blablubbabc

    Do you call player.updateInventory() afterwards?
     
  5. Offline

    MuisYa

    Try using:

    Code:
    player.updateInventory();
    whenever you are done changing the players inventory.
    If you do not update the players inventory, it will be buggy and sometimes show the update, and sometimes it just won't.
     
  6. Offline

    Cin316

    That worked! Thank you so much. Why is
    Code:java
    1. Player.updateInventory();
    deprecated even though there is no replacement method?
     
Thread Status:
Not open for further replies.

Share This Page