Cleaned up StringUtils
This commit is contained in:
@@ -72,9 +72,9 @@ public final class StringUtils {
|
||||
/**
|
||||
* String format cache.
|
||||
*/
|
||||
private static final LoadingCache<FormatLookup, String> STRING_FORMAT_CACHE = Caffeine.newBuilder()
|
||||
private static final LoadingCache<String, String> STRING_FORMAT_CACHE = Caffeine.newBuilder()
|
||||
.expireAfterAccess(10, TimeUnit.SECONDS)
|
||||
.build(StringUtils::format);
|
||||
.build(StringUtils::processFormatting);
|
||||
|
||||
/**
|
||||
* Json -> Legacy Cache.
|
||||
@@ -311,12 +311,11 @@ public final class StringUtils {
|
||||
if (option == FormatOption.WITH_PLACEHOLDERS) {
|
||||
processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, player);
|
||||
}
|
||||
FormatLookup lookup = new FormatLookup(processedMessage, player);
|
||||
return STRING_FORMAT_CACHE.get(lookup);
|
||||
return STRING_FORMAT_CACHE.get(processedMessage);
|
||||
}
|
||||
|
||||
private static String format(@NotNull final FormatLookup lookup) {
|
||||
String processedMessage = lookup.message;
|
||||
private static String processFormatting(@NotNull final String message) {
|
||||
String processedMessage = message;
|
||||
processedMessage = ChatColor.translateAlternateColorCodes('&', processedMessage);
|
||||
processedMessage = translateGradients(processedMessage);
|
||||
processedMessage = translateHexColorCodes(processedMessage);
|
||||
@@ -576,11 +575,6 @@ public final class StringUtils {
|
||||
WITHOUT_PLACEHOLDERS
|
||||
}
|
||||
|
||||
private static record FormatLookup(@NotNull String message,
|
||||
@Nullable Player player) {
|
||||
|
||||
}
|
||||
|
||||
private StringUtils() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user