Solved Removing one item from stack doesn't work when stack is already 1

Discussion in 'Plugin Development' started by WavyWonderz, Aug 24, 2013.

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

    WavyWonderz

    So I have a plugin that removes one item from a stack; however, once the stack reaches 1, that item won't disappear (I'm guessing that you can't have a stack with an amount at 0, because in that case it would just remove the stack entirely) I know I can just make an if command that tests to see if the stack is 1 then remove it... but I was wondering if there was an easier way.
    Code:
                        ItemStack hat = event.getItem().clone();
                        hat.setAmount(1);
                        event.getPlayer().getInventory().setHelmet(hat);
                        event.getItem().setAmount(event.getItem().getAmount() - 1);
                        event.getPlayer().updateInventory();
    **Fixed**

    Changed code to this...
    Code:
                        ItemStack hat = event.getItem().clone();
                        hat.setAmount(1);
                        event.getPlayer().getInventory().setHelmet(hat);
                        event.getPlayer().getInventory().removeItem(hat);
                        event.getPlayer().updateInventory();
     
Thread Status:
Not open for further replies.

Share This Page