Advertisement
MsGamerHD

Untitled

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