From 6c314350b125b340e0972f3e6b874378fc02ef72 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 22 Aug 2022 21:23:08 +0200 Subject: [PATCH] Optimized getNameWithLevel --- eco-core/core-plugin/build.gradle | 2 +- .../ecoenchants/display/EnchantmentCache.java | 26 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 81a315c8..cddf13e1 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -3,7 +3,7 @@ version rootProject.version dependencies { compileOnly project(":eco-core:core-proxy") - compileOnly 'org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT' compileOnly 'commons-io:commons-io:2.8.0' compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT' compileOnly 'net.essentialsx:EssentialsX:2.19.0' 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 941aa1e9..cafc9bee 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.JProgressBar; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -263,42 +264,45 @@ public class EnchantmentCache { */ public String getNameWithLevel(final int level, @Nullable final Player player) { - String processed = name; + StringBuilder builder = new StringBuilder(); + builder.append(name); if (enchantment instanceof EcoEnchant enchant && player != null) { if (!enchant.areRequirementsMet(player)) { - processed = PLUGIN.getDisplayModule().getOptions().getRequirementsOptions().getRequirementColor() + processed; + builder.insert(0, PLUGIN.getDisplayModule().getOptions().getRequirementsOptions().getRequirementColor()); } } if (!(enchantment.getMaxLevel() == 1 && level == 1) && level != 0) { - String numberString = " "; + StringBuilder numberString = new StringBuilder(); + numberString.append(" "); NumbersOptions numbersOptions = PLUGIN.getDisplayModule().getOptions().getNumbersOptions(); if (numbersOptions.isUseNumerals() && level < numbersOptions.getThreshold()) { - numberString += NumberUtils.toNumeral(level); + numberString.append(NumberUtils.toNumeral(level)); } else { - numberString += level; + numberString.append(level); } if (level > enchantment.getMaxLevel() && PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().isReformatAboveMaxLevel()) { if (PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().isNumbersOnly()) { String aboveMaxLevel = PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().getAboveMaxLevelFormat(); - processed = processed + aboveMaxLevel + numberString; + builder.append(aboveMaxLevel) + .append(numberString); } else { String aboveMaxLevel = PLUGIN.getDisplayModule().getOptions().getMaxLevelOptions().getAboveMaxLevelFormat(); - processed = aboveMaxLevel + processed + numberString; + builder.append(aboveMaxLevel) + .append(numberString); } } else { - processed = processed + numberString; + builder.append(numberString); } } - processed = color + processed; - processed = StringUtils.format(processed, StringUtils.FormatOption.WITHOUT_PLACEHOLDERS); - return processed; + builder.insert(0, color); + return StringUtils.format(builder.toString(), StringUtils.FormatOption.WITHOUT_PLACEHOLDERS); } /**