Advertisement
MsGamerHD

Untitled

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