Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void removeInventoryItems(Player p, Material type, int amount) {
- Inventory inv = p.getInventory();
- 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;
- }
- }
- }
- }
- public static int getItemAmount(Player p, Material type){
- Inventory inv = p.getInventory();
- int count = -1;
- for(int i = 0; i < inv.getSize(); i++){
- ItemStack is = inv.getItem(i);
- if (is != null && is.getType() == type) {
- count+=is.getAmount();
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement