From 87494afacc183efcff0a21ad3b0a4192d51dfb77 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 12 Sep 2020 15:24:45 +0100 Subject: [PATCH] Added new lore system --- .../ecoenchants/display/EnchantDisplay.java | 15 ++++++++------- .../enchantments/util/checks/EnchantChecks.java | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index 42c2c8eb..1aacaa1b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -37,6 +37,7 @@ public class EnchantDisplay { */ public static final NamespacedKey keySkip = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-skip"); + private static final String prefix = ChatColor.translateAlternateColorCodes('&',"&a&e&a&r"); private static String normalColor; private static String curseColor; @@ -94,6 +95,8 @@ public class EnchantDisplay { if(meta.hasLore()) itemLore = meta.getLore(); + if(itemLore == null) itemLore = new ArrayList<>(); + try { if (meta.getPersistentDataContainer().has(key, PersistentDataType.INTEGER)) { int enchantLoreLength = meta.getPersistentDataContainer().get(key, PersistentDataType.INTEGER); @@ -103,7 +106,7 @@ public class EnchantDisplay { } } catch (NullPointerException ignored) {} - + itemLore.removeIf((s -> s.startsWith(prefix))); if (meta instanceof EnchantmentStorageMeta) { EnchantmentStorageMeta metaBook = (EnchantmentStorageMeta) meta; @@ -200,12 +203,12 @@ public class EnchantDisplay { if(isEcoEnchant) { name = enchantment.getName(); description = EcoEnchants.getFromEnchantment(enchantment).getDescription(); - description.replaceAll(line -> descriptionColor + line); + description.replaceAll(line -> prefix + descriptionColor + line); if(!EcoEnchants.getFromEnchantment(enchantment).isEnabled()) forRemoval.add(enchantment); } else { name = ConfigManager.getLang().getString("vanilla." + enchantment.getKey().getKey() + ".name"); description = Arrays.asList(WordUtils.wrap(ConfigManager.getLang().getString("vanilla." + enchantment.getKey().getKey() + ".description"), ConfigManager.getConfig().getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n")); - description.replaceAll(line -> descriptionColor + line); + description.replaceAll(line -> prefix + descriptionColor + line); } if(!(isMaxLevelOne || type == EcoEnchant.EnchantmentType.CURSE)) { @@ -222,11 +225,11 @@ public class EnchantDisplay { } if(type == EcoEnchant.EnchantmentType.CURSE) { - curseLore.add(color + name); + curseLore.add(prefix + color + name); if(describe) curseLore.addAll(description); } else { - normalLore.add(color + name); + normalLore.add(prefix + color + name); if(describe) normalLore.addAll(description); } })); @@ -260,14 +263,12 @@ public class EnchantDisplay { metaBook.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); // Thanks ShaneBee! metaBook.addItemFlags(ItemFlag.HIDE_ENCHANTS); // Here just in case metaBook.setLore(itemLore); - metaBook.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, enchantLore.size()); item.setItemMeta(metaBook); } else { if(!meta.getEnchants().equals(oldItem.getItemMeta().getEnchants())) return oldItem; forRemoval.forEach((meta::removeEnchant)); meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); meta.setLore(itemLore); - meta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, enchantLore.size()); item.setItemMeta(meta); } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/checks/EnchantChecks.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/checks/EnchantChecks.java index 89e49a54..4b3903d0 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/checks/EnchantChecks.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/checks/EnchantChecks.java @@ -15,7 +15,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @SuppressWarnings("unchecked") -public abstract class EnchantChecks { +public final class EnchantChecks { public static boolean item(ItemStack item, Enchantment enchantment) { return getItemLevel(item, enchantment) != 0; }