Hey, when a dispenser dispenses an item, the BlockDispenseEvent triggers.
From their i get the dispenser block with.
Dispenser dispenser = (Dispesner) event.getBlock().getState();
From there, i wanna cancel the event but removing the item from the inventory too.
So i wrote following:
HashMap<Integer, ItemStack> items = dispenser.getInventory().removeItem(event.getItem());
if (items.size() == 0) event.setCancelled(true);
So the problem is now, that its only working when the dispensed itemstack has an amount that is not equal to 1 or 2. Why is it the case?