From bf7f3aac4d11c6ab34097bc836705818dcfea40f Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 27 Feb 2021 11:49:21 +0000 Subject: [PATCH] Legacy display support --- .../ecoenchants/display/EnchantDisplay.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 03928565..fdefbca2 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 @@ -30,6 +30,7 @@ import java.util.List; /** * All methods and fields pertaining to showing players the enchantments on their items. */ +@SuppressWarnings("DeprecatedIsStillUsed") public class EnchantDisplay extends DisplayModule { /** * The meta key to hide enchantments in lore. @@ -39,6 +40,15 @@ public class EnchantDisplay extends DisplayModule { @Getter private final NamespacedKey keySkip; + /** + * The legacy V key. + *

+ * Exists for backwards compatibility. + */ + @Getter + @Deprecated + private final NamespacedKey legacyV; + /** * The configurable options for displaying enchantments. */ @@ -53,6 +63,7 @@ public class EnchantDisplay extends DisplayModule { public EnchantDisplay(@NotNull final AbstractEcoPlugin plugin) { super(plugin, DisplayPriority.HIGH); keySkip = this.getPlugin().getNamespacedKeyFactory().create("ecoenchantlore-skip"); + legacyV = this.getPlugin().getNamespacedKeyFactory().create("ecoenchantlore-v"); options = new DisplayOptions(this.getPlugin()); } @@ -193,6 +204,15 @@ public class EnchantDisplay extends DisplayModule { ItemMeta meta = itemStack.getItemMeta(); + assert meta != null; + + List lore = meta.getLore() == null ? new ArrayList<>() : new ArrayList<>(meta.getLore()); + + lore.removeIf(s -> s.startsWith("§w")); + meta.setLore(lore); + + meta.getPersistentDataContainer().remove(legacyV); + if (!meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER)) { meta.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS); meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS); @@ -214,6 +234,10 @@ public class EnchantDisplay extends DisplayModule { hideEnchants = true; } + if (meta.getPersistentDataContainer().has(legacyV, PersistentDataType.INTEGER)) { + hideEnchants = false; + } + if (Display.isFinalized(itemStack)) { hideEnchants = false; }