mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-03 02:21:21 +01:00
Optimisd caching
This commit is contained in:
parent
713db5ad57
commit
1d61ba323d
@ -4,6 +4,7 @@ import com.willfp.ecoenchants.command.AbstractCommand;
|
||||
import com.willfp.ecoenchants.command.AbstractTabCompleter;
|
||||
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
@ -49,35 +50,6 @@ public final class CommandEnchantinfo extends AbstractCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
String name;
|
||||
String color;
|
||||
List<String> description;
|
||||
|
||||
boolean isCurse = enchantment.isCursed();
|
||||
boolean isSpecial = false;
|
||||
boolean isArtifact = false;
|
||||
|
||||
if(enchantment.getType().equals(EcoEnchant.EnchantmentType.SPECIAL)) {
|
||||
isSpecial = true;
|
||||
}
|
||||
if(enchantment.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT)) {
|
||||
isArtifact = true;
|
||||
}
|
||||
|
||||
if(isCurse) color = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("curse-color"));
|
||||
else if(isSpecial) color = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("special-color"));
|
||||
else if(isArtifact) color = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("artifact-color"));
|
||||
else color = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("not-curse-color"));
|
||||
|
||||
|
||||
name = enchantment.getName();
|
||||
description = EcoEnchants.getFromEnchantment(enchantment).getDescription();
|
||||
StringBuilder descriptionBuilder = new StringBuilder();
|
||||
description.forEach((line) -> {
|
||||
descriptionBuilder.append(line).append(" ");
|
||||
});
|
||||
String desc = descriptionBuilder.toString();
|
||||
|
||||
Set<String> conflictNames = new HashSet<>();
|
||||
|
||||
Set<Enchantment> conflicts = enchantment.getConflicts();
|
||||
@ -126,8 +98,8 @@ public final class CommandEnchantinfo extends AbstractCommand {
|
||||
|
||||
String maxLevel = String.valueOf(enchantment.getMaxLevel());
|
||||
|
||||
final String finalName = color + name;
|
||||
final String finalDescription = desc;
|
||||
final String finalName = EnchantDisplay.CACHE.get(enchantment).getKey();
|
||||
final String finalDescription = String.join("\n", EnchantDisplay.CACHE.get(enchantment).getValue());
|
||||
final String finalTargets = allTargets;
|
||||
final String finalConflicts = allConflicts;
|
||||
final String finalMaxLevel = maxLevel;
|
||||
|
@ -80,11 +80,14 @@ public final class EnchantDisplay {
|
||||
CACHE.clear();
|
||||
Arrays.asList(Enchantment.values()).parallelStream().forEach(enchantment -> {
|
||||
String name;
|
||||
String color;
|
||||
EcoEnchant.EnchantmentType type;
|
||||
List<String> description;
|
||||
if(EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
description = ecoEnchant.getDescription();
|
||||
name = ecoEnchant.getName();
|
||||
type = ecoEnchant.getType();
|
||||
} else {
|
||||
description = Arrays.asList(
|
||||
WordUtils.wrap(
|
||||
@ -94,7 +97,30 @@ public final class EnchantDisplay {
|
||||
).split("\\r?\\n")
|
||||
);
|
||||
name = String.valueOf(ConfigManager.getLang().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".name"));
|
||||
type = enchantment.isCursed() ? EcoEnchant.EnchantmentType.CURSE : EcoEnchant.EnchantmentType.NORMAL;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case ARTIFACT:
|
||||
color = artifactColor;
|
||||
break;
|
||||
case SPECIAL:
|
||||
color = specialColor;
|
||||
break;
|
||||
case CURSE:
|
||||
color = curseColor;
|
||||
break;
|
||||
default:
|
||||
color = normalColor;
|
||||
break;
|
||||
}
|
||||
|
||||
EnchantmentRarity rarity = EcoEnchants.getFromEnchantment(enchantment).getRarity();
|
||||
if(rarity.hasCustomColor() && type != EcoEnchant.EnchantmentType.CURSE) {
|
||||
color = rarity.getCustomColor();
|
||||
}
|
||||
|
||||
name = color + name;
|
||||
description.replaceAll(line -> prefix + descriptionColor + line);
|
||||
CACHE.put(enchantment, new Pair<>(name, description));
|
||||
});
|
||||
@ -199,33 +225,8 @@ public final class EnchantDisplay {
|
||||
boolean isEcoEnchant = EcoEnchants.getFromEnchantment(enchantment) != null;
|
||||
|
||||
String name = CACHE.get(enchantment).getKey();
|
||||
String color;
|
||||
EcoEnchant.EnchantmentType type;
|
||||
|
||||
if(isEcoEnchant) type = EcoEnchants.getFromEnchantment(enchantment).getType();
|
||||
else type = enchantment.isCursed() ? EcoEnchant.EnchantmentType.CURSE : EcoEnchant.EnchantmentType.NORMAL;
|
||||
|
||||
switch(type) {
|
||||
case ARTIFACT:
|
||||
color = artifactColor;
|
||||
break;
|
||||
case SPECIAL:
|
||||
color = specialColor;
|
||||
break;
|
||||
case CURSE:
|
||||
color = curseColor;
|
||||
break;
|
||||
default:
|
||||
color = normalColor;
|
||||
break;
|
||||
}
|
||||
|
||||
if(isEcoEnchant) {
|
||||
EnchantmentRarity rarity = EcoEnchants.getFromEnchantment(enchantment).getRarity();
|
||||
if(rarity.hasCustomColor() && type != EcoEnchant.EnchantmentType.CURSE) {
|
||||
color = rarity.getCustomColor();
|
||||
}
|
||||
|
||||
if(!EcoEnchants.getFromEnchantment(enchantment).isEnabled()) forRemoval.add(enchantment);
|
||||
}
|
||||
|
||||
@ -237,7 +238,7 @@ public final class EnchantDisplay {
|
||||
}
|
||||
}
|
||||
|
||||
lore.add(prefix + color + name);
|
||||
lore.add(prefix + name);
|
||||
if(enchantments.size() <= describeThreshold && useDescribe)
|
||||
lore.addAll(CACHE.get(enchantment).getValue());
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user