Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean removeItemInv(Player p, Material type, int amount) {
- if(getItemAmount(p, type) >= amount){
- for(int i = 0; i < amount; i++){
- removeOneItem(p, type);
- }
- return true;
- }
- return false;
- }
- public static void removeOneItem(Player p, Material type) {
- Inventory inv = p.getInventory();
- for (ItemStack is : inv.getContents()) {
- if (is != null && is.getType() == type) {
- int amount = is.getAmount()-1;
- if (amount > 0) {
- is.setAmount(amount);
- break;
- } else {
- is.setType(Material.AIR);
- }
- }
- }
- }
- public static int getItemAmount(Player p, Material type){
- Inventory inv = p.getInventory();
- int count = -1;
- for (ItemStack is : inv.getContents()) {
- if (is != null && is.getType() == type) {
- count+=is.getAmount();
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement