From 8e7d7288ae94e7face6f0b7718c14f8e15c76b3d Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 29 Oct 2020 14:01:57 +0000 Subject: [PATCH] Reworked cache --- .../ecoenchants/display/EnchantDisplay.java | 2 + .../ecoenchants/display/EnchantmentCache.java | 48 +++++++------------ 2 files changed, 19 insertions(+), 31 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 63f004d0..a4ebe8c6 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -88,6 +88,8 @@ public final class EnchantDisplay { shrinkThreshold = ConfigManager.getConfig().getInt("lore.shrink.after-lines"); useShrink = ConfigManager.getConfig().getBool("lore.shrink.enabled"); shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line"); + + EnchantmentCache.update(); } /** diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java index dca54f46..0435d778 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java @@ -13,10 +13,6 @@ import java.util.*; public class EnchantmentCache { private static final Set CACHE = new HashSet<>(); - static { - update(); - } - public static CacheEntry getEntry(Enchantment enchantment) { Optional matching = CACHE.stream().filter(enchant -> enchant.getEnchantment().getKey().equals(enchantment.getKey())).findFirst(); return matching.orElse(new CacheEntry(enchantment, enchantment.getKey().getKey(), enchantment.getKey().getKey(), Collections.singletonList("No Description Found"))); @@ -82,15 +78,28 @@ public class EnchantmentCache { public static class CacheEntry { private final Enchantment enchantment; - private String name; - private String rawName; - private List description; + private final String name; + private final String rawName; + private final List description; + private final String stringDescription; public CacheEntry(Enchantment enchantment, String name, String rawName, List description) { this.enchantment = enchantment; this.name = name; this.rawName = rawName; this.description = description; + + + StringBuilder descriptionBuilder = new StringBuilder(); + + description.forEach(s -> { + descriptionBuilder.append(s); + descriptionBuilder.append(" "); + }); + + String stringDescription = descriptionBuilder.toString(); + stringDescription = stringDescription.replaceAll("§w", ""); + this.stringDescription = stringDescription.replaceAll(EnchantDisplay.descriptionColor, ""); } public Enchantment getEnchantment() { @@ -110,30 +119,7 @@ public class EnchantmentCache { } public String getStringDescription() { - StringBuilder descriptionBuilder = new StringBuilder(); - - EnchantmentCache.getEntry(enchantment).getDescription().forEach(s -> { - descriptionBuilder.append(s); - descriptionBuilder.append(" "); - }); - - String description = descriptionBuilder.toString(); - description = description.replaceAll("§w", ""); - description = description.replaceAll(EnchantDisplay.descriptionColor, ""); - - return description; - } - - public void setName(String name) { - this.name = name; - } - - public void setRawName(String rawName) { - this.rawName = rawName; - } - - public void setDescription(List description) { - this.description = description; + return stringDescription; } } }