Optimized getNameWithLevel

This commit is contained in:
Auxilor 2022-08-22 21:23:08 +02:00
parent ae63af4683
commit 6c314350b1
2 changed files with 16 additions and 12 deletions

View File

@ -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'

View File

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