diff --git a/build.gradle b/build.gradle index d3da970..b3ff759 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/src/main/scala/io/izzel/taboolib/cronus/bukkit/ItemStack.java b/src/main/scala/io/izzel/taboolib/cronus/bukkit/ItemStack.java index e2c594a..92aade4 100644 --- a/src/main/scala/io/izzel/taboolib/cronus/bukkit/ItemStack.java +++ b/src/main/scala/io/izzel/taboolib/cronus/bukkit/ItemStack.java @@ -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() { diff --git a/src/main/scala/io/izzel/taboolib/util/item/Items.java b/src/main/scala/io/izzel/taboolib/util/item/Items.java index f6fde5e..3989451 100644 --- a/src/main/scala/io/izzel/taboolib/util/item/Items.java +++ b/src/main/scala/io/izzel/taboolib/util/item/Items.java @@ -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); }