Advertisement
MsGamerHD

Untitled

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