This commit is contained in:
坏黑 2019-08-15 10:47:56 +08:00
parent fa432ff741
commit bf809208ae
3 changed files with 5 additions and 32 deletions

View File

@ -5,7 +5,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '4.0.4'
}
group = 'me.skymc'
version = '5.01'
version = '5.02'
sourceCompatibility = 1.8
targetCompatibility = 1.8

View File

@ -1,7 +1,6 @@
package io.izzel.taboolib.cronus.bukkit;
import io.izzel.taboolib.util.item.Items;
import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
@ -49,37 +48,11 @@ public class ItemStack {
}
public boolean hasItem(Player player) {
int checkAmount = amount;
for (org.bukkit.inventory.ItemStack itemStack : player.getInventory().getContents()) {
if (itemStack != null && !itemStack.getType().equals(Material.AIR) && isItem(itemStack)) {
checkAmount -= itemStack.getAmount();
if (checkAmount <= 0) {
return true;
}
}
}
return false;
return Items.hasItem(player.getInventory(), this::isItem, amount);
}
public boolean takeItem(Player player) {
int takeAmount = amount;
org.bukkit.inventory.ItemStack[] contents = player.getInventory().getContents();
for (int i = 0; i < contents.length; i++) {
org.bukkit.inventory.ItemStack itemStack = contents[i];
if (itemStack != null && !itemStack.getType().equals(Material.AIR) && isItem(itemStack)) {
takeAmount -= itemStack.getAmount();
if (takeAmount < 0) {
itemStack.setAmount(itemStack.getAmount() - (takeAmount + itemStack.getAmount()));
return true;
} else {
player.getInventory().setItem(i, null);
if (takeAmount == 0) {
return true;
}
}
}
}
return false;
return Items.takeItem(player.getInventory(), this::isItem, amount);
}
public String getType() {

View File

@ -164,7 +164,7 @@ public class Items {
}
public static boolean checkItem(Player player, ItemStack item, int amount, boolean remove) {
return hasItem(player.getInventory(), i -> i.isSimilar(item), amount);
return remove ? takeItem(player.getInventory(), i -> i.isSimilar(item), amount) : hasItem(player.getInventory(), i -> i.isSimilar(item), amount);
}
public static boolean checkItem(Inventory inventory, ItemStack item, int amount, boolean remove) {
@ -321,7 +321,7 @@ public class Items {
return NMS.handle().saveNBT(item, nbt);
}
interface Matcher {
public interface Matcher {
boolean match(ItemStack item);
}