From 640e6c5d7dab1f9e259ff8eec0bf82a5bf1f28fc Mon Sep 17 00:00:00 2001 From: xGinko Date: Mon, 4 Mar 2024 23:05:18 +0100 Subject: [PATCH] fix chatcolor parsing on folia --- .../anarchyexploitfixes/AnarchyExploitFixes.java | 5 ++++- .../config/LanguageCache.java | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java index 5f14db25c..0657a35bc 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java @@ -15,7 +15,10 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.Locale; +import java.util.Set; import java.util.jar.JarFile; import java.util.logging.Logger; import java.util.regex.Matcher; diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/LanguageCache.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/LanguageCache.java index 548aead93..32bb8d4ab 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/LanguageCache.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/LanguageCache.java @@ -7,11 +7,12 @@ import java.io.File; import java.util.List; +import java.util.Locale; public class LanguageCache { private final ConfigFile lang; - + private final Locale locale; public final Component no_permission, invalid_syntax, failed_argument_parse, chat_commandwhitelist_badcommand, misc_joinMessage, misc_leaveMessage, misc_MaskedKickMessage, preventions_witherSpawningDisabledInRadius, misc_enabledConnectionMsgs, misc_disabledConnectionMsgs, elytra_disablePacketElytraFly, elytra_global_YouAreFlyingIn, elytra_global_New, elytra_global_New_UpperCase, elytra_global_New_Color, elytra_global_Old, elytra_global_Old_UpperCase, @@ -24,6 +25,7 @@ public class LanguageCache { public final List misc_firstJoinMessage, help_Message; public LanguageCache(String locale) throws Exception { + this.locale = Locale.forLanguageTag(locale.replace("_", "-")); AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); File langYML = new File(plugin.getDataFolder() + File.separator + "lang", locale + ".yml"); // Check if the lang folder has already been created @@ -133,28 +135,28 @@ public LanguageCache(String locale) throws Exception { public Component getTranslation(String path, String defaultTranslation, boolean upperCase) { lang.addDefault(path, defaultTranslation); - defaultTranslation = translateChatColor(defaultTranslation); - return MiniMessage.miniMessage().deserialize(upperCase ? lang.getString(path, defaultTranslation).toUpperCase() : lang.getString(path, defaultTranslation)); + final String serialized = translateChatColor(lang.getString(path, defaultTranslation)); + return MiniMessage.miniMessage().deserialize(upperCase ? serialized.toUpperCase(locale) : serialized); } public Component getTranslation(String path, String defaultTranslation, boolean upperCase, String comment) { lang.addDefault(path, defaultTranslation, comment); - defaultTranslation = translateChatColor(defaultTranslation); - return MiniMessage.miniMessage().deserialize(upperCase ? lang.getString(path, defaultTranslation).toUpperCase() : lang.getString(path, defaultTranslation)); + final String serialized = translateChatColor(lang.getString(path, defaultTranslation)); + return MiniMessage.miniMessage().deserialize(upperCase ? serialized.toUpperCase(locale) : serialized); } public List getListTranslation(String path, List defaultTranslation, boolean upperCase) { lang.addDefault(path, defaultTranslation); return lang.getStringList(path).stream() .map(LanguageCache::translateChatColor) - .map(line -> MiniMessage.miniMessage().deserialize(upperCase ? line.toUpperCase() : line)).toList(); + .map(serialized -> MiniMessage.miniMessage().deserialize(upperCase ? serialized.toUpperCase(locale) : serialized)).toList(); } public List getListTranslation(String path, List defaultTranslation, boolean upperCase, String comment) { lang.addDefault(path, defaultTranslation, comment); return lang.getStringList(path).stream() .map(LanguageCache::translateChatColor) - .map(line -> MiniMessage.miniMessage().deserialize(upperCase ? line.toUpperCase() : line)).toList(); + .map(serialized -> MiniMessage.miniMessage().deserialize(upperCase ? serialized.toUpperCase(locale) : serialized)).toList(); } private static String translateChatColor(String string) {