Created
April 22, 2013 10:32
-
-
Save ChristianGaertner/5433818 to your computer and use it in GitHub Desktop.
Remove one single item from Players Inventory
depends on the Bukkit API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)