From 9f5d84d81cc9c0db6844af6fca4a095cc665ada9 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 5 Oct 2021 09:00:08 +0100 Subject: [PATCH] Changed color system to remove terrible {} syntax and replace with minimessage --- .../ecoenchants/display/EnchantmentCache.java | 59 +++++-------------- .../core-plugin/src/main/resources/lang.yml | 2 +- 2 files changed, 17 insertions(+), 44 deletions(-) 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 60e77ca5..bdaf4e6c 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 @@ -22,6 +22,7 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.border.MatteBorder; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -263,27 +264,15 @@ public class EnchantmentCache { */ public String getNameWithLevel(final int level, @Nullable final Player player) { - String formattedName = name; - String unformattedName = name; + String processed = name; + if (enchantment instanceof EcoEnchant enchant && player != null) { if (!enchant.areRequirementsMet(player)) { - String color = PLUGIN.getDisplayModule().getOptions().getRequirementsOptions().getRequirementColor(); - if (color.contains("{}")) { - unformattedName = color.replace("{}", unformattedName); - formattedName = color.replace("{}", formattedName); - } else { - unformattedName = color + unformattedName; - formattedName = color + formattedName; - } + processed = PLUGIN.getDisplayModule().getOptions().getRequirementsOptions().getRequirementColor() + processed; } } - if (color.contains("{}")) { - formattedName = color.replace("{}", formattedName); - } else { - formattedName = color + formattedName; - } - formattedName = StringUtils.format(formattedName); - if (!(enchantment.getMaxLevel() == 1 && level == 1)) { + + if (!(enchantment.getMaxLevel() == 1 && level == 1) && level != 0) { String numberString = " "; NumbersOptions numbersOptions = PLUGIN.getDisplayModule().getOptions().getNumbersOptions(); @@ -296,30 +285,21 @@ public class EnchantmentCache { if (level > enchantment.getMaxLevel() && PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().isReformatAboveMaxLevel()) { if (PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().isNumbersOnly()) { - String color = PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().getAboveMaxLevelFormat(); - if (color.contains("{}")) { - numberString = color.replace("{}", numberString); - } else { - numberString = color + numberString; - } + String aboveMaxLevel = PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().getAboveMaxLevelFormat(); - return formattedName + StringUtils.format(numberString); + processed = processed + aboveMaxLevel + numberString; } else { - String clone = unformattedName; - String color = PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().getAboveMaxLevelFormat(); - if (color.contains("{}")) { - clone = color.replace("{}", clone); - } else { - clone = color + clone; - } - return StringUtils.format(clone + numberString); + String aboveMaxLevel = PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().getAboveMaxLevelFormat(); + processed = aboveMaxLevel + processed + numberString; } } else { - return formattedName + numberString; + processed = processed + numberString; } - } else { - return formattedName; } + + processed = color + processed; + processed = StringUtils.format(processed, StringUtils.FormatOption.WITHOUT_PLACEHOLDERS); + return processed; } /** @@ -416,14 +396,7 @@ public class EnchantmentCache { * @return The name. */ public String getName() { - String formattedName = name; - if (color.contains("{}")) { - formattedName = color.replace("{}", formattedName); - } else { - formattedName = color + formattedName; - } - - return StringUtils.format(formattedName); + return getNameWithLevel(0); } } } diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 3cbacab0..c3596666 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -35,7 +35,7 @@ messages: no-targets: "&cCannot be applied" no-conflicts: "&cNo conflicts" -missing-requirements-format: "&m" +missing-requirements-format: "" curse-color: "&c" normal-color: "&7"