mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-27 20:37:34 +01:00
Reworked cache
This commit is contained in:
parent
7f4a643a54
commit
8e7d7288ae
@ -88,6 +88,8 @@ public final class EnchantDisplay {
|
|||||||
shrinkThreshold = ConfigManager.getConfig().getInt("lore.shrink.after-lines");
|
shrinkThreshold = ConfigManager.getConfig().getInt("lore.shrink.after-lines");
|
||||||
useShrink = ConfigManager.getConfig().getBool("lore.shrink.enabled");
|
useShrink = ConfigManager.getConfig().getBool("lore.shrink.enabled");
|
||||||
shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line");
|
shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line");
|
||||||
|
|
||||||
|
EnchantmentCache.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,10 +13,6 @@ import java.util.*;
|
|||||||
public class EnchantmentCache {
|
public class EnchantmentCache {
|
||||||
private static final Set<CacheEntry> CACHE = new HashSet<>();
|
private static final Set<CacheEntry> CACHE = new HashSet<>();
|
||||||
|
|
||||||
static {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CacheEntry getEntry(Enchantment enchantment) {
|
public static CacheEntry getEntry(Enchantment enchantment) {
|
||||||
Optional<CacheEntry> matching = CACHE.stream().filter(enchant -> enchant.getEnchantment().getKey().equals(enchantment.getKey())).findFirst();
|
Optional<CacheEntry> 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")));
|
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 {
|
public static class CacheEntry {
|
||||||
private final Enchantment enchantment;
|
private final Enchantment enchantment;
|
||||||
private String name;
|
private final String name;
|
||||||
private String rawName;
|
private final String rawName;
|
||||||
private List<String> description;
|
private final List<String> description;
|
||||||
|
private final String stringDescription;
|
||||||
|
|
||||||
public CacheEntry(Enchantment enchantment, String name, String rawName, List<String> description) {
|
public CacheEntry(Enchantment enchantment, String name, String rawName, List<String> description) {
|
||||||
this.enchantment = enchantment;
|
this.enchantment = enchantment;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.rawName = rawName;
|
this.rawName = rawName;
|
||||||
this.description = description;
|
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() {
|
public Enchantment getEnchantment() {
|
||||||
@ -110,30 +119,7 @@ public class EnchantmentCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getStringDescription() {
|
public String getStringDescription() {
|
||||||
StringBuilder descriptionBuilder = new StringBuilder();
|
return stringDescription;
|
||||||
|
|
||||||
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<String> description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user