From 4fa90fabd51f6c8a7439283ac624ef5bddccb04c Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 21 Dec 2021 14:50:13 +0000 Subject: [PATCH] Cleaned up EcoEnchants#hasAnyOfType --- .../ecoenchants/enchantments/EcoEnchants.java | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index edc3c718..ee3e33f3 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -4,6 +4,7 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableList; import com.willfp.eco.core.config.updating.ConfigUpdater; +import com.willfp.eco.core.fast.FastItemStack; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.AngerArtifact; import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.AshArtifact; @@ -247,13 +248,11 @@ import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantments; import lombok.experimental.UtilityClass; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; @UtilityClass @SuppressWarnings({"unused", "checkstyle:JavadocVariable"}) @@ -552,22 +551,11 @@ public class EcoEnchants { */ public static boolean hasAnyOfType(@NotNull final ItemStack item, @NotNull final EnchantmentType type) { - AtomicBoolean hasOfType = new AtomicBoolean(false); - - if (item.getItemMeta() instanceof EnchantmentStorageMeta) { - ((EnchantmentStorageMeta) item.getItemMeta()).getStoredEnchants().forEach(((enchantment, integer) -> { - if (enchantment instanceof EcoEnchant ecoEnchant && ecoEnchant.getType().equals(type)) { - hasOfType.set(true); - } - })); - } else { - item.getEnchantments().forEach((enchantment, integer) -> { - if (enchantment instanceof EcoEnchant ecoEnchant && ecoEnchant.getType().equals(type)) { - hasOfType.set(true); - } - }); - } - return hasOfType.get(); + return FastItemStack.wrap(item).getEnchantmentsOnItem(true).keySet() + .stream() + .filter(enchantment -> enchantment instanceof EcoEnchant) + .map(enchantment -> (EcoEnchant) enchantment) + .anyMatch(ecoEnchant -> ecoEnchant.getType().equals(type)); } /**