Skip to content

Instantly share code, notes, and snippets.

@ChristianGaertner
Created April 22, 2013 10:32
Show Gist options
  • Save ChristianGaertner/5433818 to your computer and use it in GitHub Desktop.
Save ChristianGaertner/5433818 to your computer and use it in GitHub Desktop.
Remove one single item from Players Inventory depends on the Bukkit API
public static void removeInventoryItems(PlayerInventory inv, Material type, int amount) {
for (ItemStack is : inv.getContents()) {
if (is != null && is.getType() == type) {
int newamount = is.getAmount() - amount;
if (newamount > 0) {
is.setAmount(newamount);
break;
} else {
inv.remove(is);
amount = -newamount;
if (amount == 0) break;
}
}
}
}
@IceNbrn
Copy link

IceNbrn commented May 26, 2017

i have a problem when i use this function: if i have 2 items (1 stone, 1 stone) and the amount is 1, what happens he removes 2 items, but the amount is 1.
(yes i know i have a bad english, sry)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment