From 6d0ac359a72bb0b06b34e554d082e305e35f44a0 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 25 Feb 2021 18:02:26 +0000 Subject: [PATCH] Fixed HideEnchants (requires eco 4.2.0) --- build.gradle | 2 +- .../ecoenchants/display/EnchantDisplay.java | 40 +++++++++---------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 8230b5e2..1ddaa5d4 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:4.0.0' + compileOnly 'com.willfp:eco:4.2.0' compileOnly 'org.jetbrains:annotations:19.0.0' diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index 8f61cfdb..9c13e38c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -65,7 +65,8 @@ public class EnchantDisplay extends DisplayModule { } @Override - protected void display(@NotNull final ItemStack itemStack) { + protected void display(@NotNull final ItemStack itemStack, + @NotNull final Object... args) { if (!EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) { return; } @@ -74,10 +75,7 @@ public class EnchantDisplay extends DisplayModule { assert meta != null; - boolean hide = false; - if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) { - hide = true; - } + boolean hide = (boolean) args[0]; List itemLore = null; @@ -133,6 +131,7 @@ public class EnchantDisplay extends DisplayModule { forRemoval.add(enchantment); } }); + forRemoval.forEach(enchantment -> { enchantments.remove(enchantment); if (meta instanceof EnchantmentStorageMeta) { @@ -179,6 +178,7 @@ public class EnchantDisplay extends DisplayModule { if (meta instanceof EnchantmentStorageMeta) { meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); } + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); lore.addAll(itemLore); meta.setLore(lore); @@ -192,31 +192,27 @@ public class EnchantDisplay extends DisplayModule { } ItemMeta meta = itemStack.getItemMeta(); - List itemLore; - - if (meta.hasLore()) { - itemLore = meta.getLore(); - } else { - itemLore = new ArrayList<>(); - } - - if (itemLore == null) { - itemLore = new ArrayList<>(); - } - - itemLore.removeIf(s -> s.startsWith("§w")); - - meta.setLore(itemLore); if (!meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER)) { meta.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS); meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS); } + meta.getPersistentDataContainer().remove(keySkip); itemStack.setItemMeta(meta); + } - if (itemStack.getItemMeta() == null) { - return; + @Override + protected Object[] generateVarArgs(@NotNull final ItemStack itemStack) { + ItemMeta meta = itemStack.getItemMeta(); + if (meta == null) { + return new Object[0]; } + boolean hideEnchants = false; + if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) { + hideEnchants = true; + } + + return new Object[]{hideEnchants}; } }