Added above-max-level-color

This commit is contained in:
Auxilor 2021-08-10 14:32:34 +01:00
parent 4be58ced42
commit d3dd673fb6
5 changed files with 85 additions and 10 deletions

View File

@ -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()) {

View File

@ -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.
*

View File

@ -34,6 +34,11 @@ public class DisplayOptions extends PluginDependent<EcoPlugin> {
*/
@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<EcoPlugin> {
descriptionOptions.update();
numbersOptions.update();
shrinkOptions.update();
maxLevelOptions.update();
sortedTypes.clear();
sortedTypes.addAll(this.getPlugin().getConfigYml().getStrings("lore.type-ordering").stream()

View File

@ -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<EcoPlugin> {
/**
* 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);
}
}

View File

@ -40,6 +40,8 @@ special-color: "<gradient:FB57EC>{}</gradient:EF1DEC>&d"
artifact-color: "<gradient:CAC531>{}</gradient:F3F9A7>&e"
spell-color: "<gradient:0575E6>{}</gradient:021B79>&9"
above-max-level-color: "<gradient:#1D976C>{}</gradient:#93F9B9>"
description-color: "&8"
special-particle-color: "#FF69B4"