From d3dd673fb6ef7b9b8cf841c3bd0b15432e07976f Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 10 Aug 2021 14:32:34 +0100 Subject: [PATCH] Added above-max-level-color --- .../ecoenchants/display/EnchantDisplay.java | 11 +----- .../ecoenchants/display/EnchantmentCache.java | 38 +++++++++++++++++++ .../display/options/DisplayOptions.java | 6 +++ .../display/options/MaxLevelOptions.java | 38 +++++++++++++++++++ .../core-plugin/src/main/resources/lang.yml | 2 + 5 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/MaxLevelOptions.java 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 3d155768..aeca628b 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 @@ -6,7 +6,6 @@ import com.willfp.eco.core.display.Display; import com.willfp.eco.core.display.DisplayModule; import com.willfp.eco.core.display.DisplayPriority; import com.willfp.eco.core.fast.FastItemStack; -import com.willfp.eco.util.NumberUtils; import com.willfp.ecoenchants.display.options.DisplayOptions; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.util.ItemConversionOptions; @@ -119,15 +118,7 @@ public class EnchantDisplay extends DisplayModule { unsorted.forEach(enchantment -> enchantments.put(enchantment, tempEnchantments.get(enchantment))); enchantments.forEach((enchantment, level) -> { - String name = EnchantmentCache.getEntry(enchantment).getName(); - - if (!(enchantment.getMaxLevel() == 1 && level == 1)) { - if (options.getNumbersOptions().isUseNumerals() && level < options.getNumbersOptions().getThreshold()) { - name += " " + NumberUtils.toNumeral(level); - } else { - name += " " + level; - } - } + String name = EnchantmentCache.getEntry(enchantment).getNameWithLevel(level); lore.add(Display.PREFIX + name); if (!options.getDescriptionOptions().isShowingAtBottom()) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java index 4698a4fc..3ffc3068 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java @@ -3,8 +3,10 @@ package com.willfp.ecoenchants.display; import com.google.common.collect.ImmutableMap; import com.willfp.eco.core.config.updating.ConfigUpdater; import com.willfp.eco.core.display.Display; +import com.willfp.eco.util.NumberUtils; import com.willfp.eco.util.StringUtils; import com.willfp.ecoenchants.EcoEnchantsPlugin; +import com.willfp.ecoenchants.display.options.NumbersOptions; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; @@ -238,6 +240,42 @@ public class EnchantmentCache { } } + /** + * Get enchantment with level. + * + * @param level The level. + * @return The name with the level. + */ + public String getNameWithLevel(final int level) { + if (!(enchantment.getMaxLevel() == 1 && level == 1)) { + String numberString = " "; + + NumbersOptions numbersOptions = PLUGIN.getDisplayModule().getOptions().getNumbersOptions(); + + if (numbersOptions.isUseNumerals() && level < numbersOptions.getThreshold()) { + numberString += NumberUtils.toNumeral(level); + } else { + numberString += level; + } + + String appendedName = name + numberString; + + if (level > enchantment.getMaxLevel() && PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().isReformatAboveMaxLevel()) { + String color = PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().getAboveMaxLevelFormat(); + if (color.contains("{}")) { + appendedName = color.replace("{}", name); + } else { + appendedName = color + name; + } + + appendedName = StringUtils.format(name); + } + return appendedName; + } + + return name; + } + /** * Get the description of an enchantment at a certain level. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java index 96ce299c..5845edb6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java @@ -34,6 +34,11 @@ public class DisplayOptions extends PluginDependent { */ @Getter private final ShrinkOptions shrinkOptions = new ShrinkOptions(this.getPlugin()); + /** + * The max level options being used. + */ + @Getter + private final MaxLevelOptions maxLevelOptions = new MaxLevelOptions(this.getPlugin()); /** * The enchantment types, sorted according to config. */ @@ -74,6 +79,7 @@ public class DisplayOptions extends PluginDependent { descriptionOptions.update(); numbersOptions.update(); shrinkOptions.update(); + maxLevelOptions.update(); sortedTypes.clear(); sortedTypes.addAll(this.getPlugin().getConfigYml().getStrings("lore.type-ordering").stream() diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/MaxLevelOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/MaxLevelOptions.java new file mode 100644 index 00000000..ad209419 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/MaxLevelOptions.java @@ -0,0 +1,38 @@ +package com.willfp.ecoenchants.display.options; + +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.PluginDependent; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +public class MaxLevelOptions extends PluginDependent { + + /** + * If enchantments should have a different format above max level. + */ + @Getter + private boolean reformatAboveMaxLevel; + + /** + * The above max level format. + */ + @Getter + private String aboveMaxLevelFormat; + + /** + * Create new description options. + * + * @param plugin EcoEnchants. + */ + public MaxLevelOptions(@NotNull final EcoPlugin plugin) { + super(plugin); + } + + /** + * Update the options. + */ + public void update() { + reformatAboveMaxLevel = this.getPlugin().getConfigYml().getBool("lore.above-max-level.reformat"); + aboveMaxLevelFormat = this.getPlugin().getLangYml().getString("above-max-level-color", false); + } +} diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 328cef2e..b175ce3e 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -40,6 +40,8 @@ special-color: "{}&d" artifact-color: "{}&e" spell-color: "{}&9" +above-max-level-color: "{}" + description-color: "&8" special-particle-color: "#FF69B4"