Removing only 1 item...?

Discussion in 'Plugin Development' started by Eggspurt, Jul 21, 2015.

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

    Eggspurt

    Code:
        Material item = p.getItemInHand().getType();
         ItemStack remove = new ItemStack(item, 1);
        p.getInventory().remove(remove);
         p.updateInventory();
    
    It doesn't remove the item in the users hand for some reason, any ideas?
     
  2. Offline

    RoyalNinja

    Ok so first of all your current method of saving the item stack is very unefficent and probably the cause for your issue. There is no need to cast to a material then to an item stack. Cast the item in hand simply to an item stack.

    Then you eant to check how much of the item the player has so

    itemstack.getAmount();

    Then you want to check with an if statement if the amount is 1, if it is then you want to simply set the item to null

    If not then do

    itemstack.setAmount(itemstack.getAmount - 1);
     
  3. Offline

    Konato_K

    @Eggspurt If you just want to remove their item in hand then do Player#setItemInHand(null)
     
  4. Offline

    BrickBoy55

    @Eggspurt I've had this problem before. Don't use remove, use removeItem.
     
Thread Status:
Not open for further replies.

Share This Page