public static boolean removeInventoryItems(PlayerInventory inv, ItemStack item) { for (ItemStack is : inv.getContents()) { if (is != null && is.getItemMeta().equals(item.getItemMeta())) { int amount = item.getAmount(); int newamount = is.getAmount() - amount; if (newamount > 0) { is.setAmount(newamount); return true; } if (newamount == 0) { inv.removeItem(is); return true; } } } return false; }