Advertisement
MsGamerHD

Untitled

Jul 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1.     public static void removeInventoryItems(Player p, Material type, int amount) {
  2.         Inventory inv = p.getInventory();
  3.        
  4.         for (ItemStack is : inv.getContents()) {
  5.             if (is != null && is.getType() == type) {
  6.                 int newamount = is.getAmount() - amount;
  7.                 if (newamount > 0) {
  8.                     is.setAmount(newamount);
  9.                     break;
  10.                 } else {
  11.                     inv.remove(is);
  12.                     amount = -newamount;
  13.                     if (amount == 0) break;
  14.                 }
  15.             }
  16.         }
  17.     }
  18.    
  19.     public static int getItemAmount(Player p, Material type){
  20.         Inventory inv = p.getInventory();
  21.         int count = -1;
  22.        
  23.         for(int i = 0; i < inv.getSize(); i++){
  24.             ItemStack is = inv.getItem(i);
  25.             if (is != null && is.getType() == type) {
  26.                 count+=is.getAmount();
  27.             }
  28.         }
  29.        
  30.         return count;
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement