Solved item won't remove?

Discussion in 'Plugin Development' started by MeTim, Sep 9, 2013.

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

    MeTim

    Hey guys i have tried in many ways to remove the item in hand and this is my code now:
    Code:
                                    if (event.getPlayer().getItemInHand().getAmount() <= 1) {
                                        event.getPlayer().getInventory().setItemInHand(null);
                                        event.getPlayer().sendMessage("1");
                                    } else {
                                        event.getPlayer().getItemInHand().setAmount(event.getPlayer().getItemInHand().getAmount() - 1);
                                        event.getPlayer().sendMessage("2");
                                    }
    i have tried removeItem(iteminhand) and many more things and it just won't work (i only get the number 1 in the chat so that's not the problem.) I hope you guys can help me :D?
     
  2. Offline

    tommycake50

    event.getPlayer().updateInventory();
    is required(And use .removeItem()).
     
  3. Offline

    sharp237

  4. Offline

    MeTim

    i now have this but it still won't work. (It removes it till there's 1 item left and my item has a lore i don't know if that's a problem?)
    Code:
        if (event.getPlayer().getItemInHand().getAmount() <= 1) {
                                        event.getPlayer().getInventory().removeItem(event.getPlayer().getItemInHand());
                                        event.getPlayer().updateInventory();
                                    } else {
                                        event.getPlayer().getItemInHand().setAmount(event.getPlayer().getItemInHand().getAmount() - 1);
                                    }
    Oh and when i clear the inventory everything (except armor) is removed but not the item in my hand.

    fixed it! added a bukkitrunnable with a delay of 1 tick and then removed the item :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page