Solved Removing items from inventory

Discussion in 'Spigot Plugin Development' started by MarcusSlover, Mar 21, 2020.

  1. Hi all, so I made a shop where you sell certain items, but the items are not removing from my inventory.
    I didn't use .removeItem() because I wanted to make a custom thing. And it doesn't work: just saying this worked on 1.12.2 but 1.15.2 doesn't seem to work.

    Code above is inside of click event, and yes it's registered.


    After I click it this happens:

    The carrot item just moves in my inventory and I get money.

    Does anybody know how to fix this?
  2. Hello,

    I have a nice Method for you. :)

    Code (Java):
        public static boolean consumeItem(Player player, int count, Material mat) {
            Map<Integer, ? extends ItemStack> ammo = player.getInventory().all(mat);

            int found = 0;
            for (ItemStack stack : ammo.values())
                found += stack.getAmount();
            if (count > found) {
                return false;

            for (Integer index : ammo.keySet()) {
                ItemStack stack = ammo.get(index);

                int removed = Math.min(count, stack.getAmount());
                count -= removed;

                if (stack.getAmount() == removed) {
                    player.getInventory().setItem(index, null);
                } else {
                    stack.setAmount(stack.getAmount() - removed);

                if (count <= 0) {

            return true;
    • Funny Funny x 1
    • Winner Winner x 1
  3. I'm going to test it
  4. The same thing happens, the item is like going back to my Hotbar and it's not being removed :c
  5. That's weird, are there any errors in the console?
  6. Nope