From b1dc8dfc7cb6401ee30e70ce8d93bea97b8c7f5c Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:02:11 +0700 Subject: [PATCH] Add fallback on translate (ComponentUtilities) --- .../me/chayapak1/chomens_bot/util/ComponentUtilities.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java b/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java index 1dc830d..136a6ad 100644 --- a/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java +++ b/src/main/java/me/chayapak1/chomens_bot/util/ComponentUtilities.java @@ -81,13 +81,15 @@ public class ComponentUtilities { return map; } - private static String getOrReturnKey (String key) { + private static String getOrReturnFallback (TranslatableComponent component) { + final String key = component.key(); + final String minecraftKey = language.get(key); final String voiceChatKey = voiceChatLanguage.get(key); if (minecraftKey != null) return minecraftKey; else if (voiceChatKey != null) return voiceChatKey; - else return key; + else return component.fallback() != null ? component.fallback() : key; } public static String stringify (Component message) { return stringify(message, null); } @@ -264,7 +266,7 @@ public class ComponentUtilities { } public static PartiallyStringified stringifyPartially (TranslatableComponent message, boolean motd, boolean ansi, String lastColor, boolean noHex) { - String format = getOrReturnKey(message.key()); + String format = getOrReturnFallback(message); // totallynotskidded™️ from HBot (and changed a bit) Matcher matcher = ARG_PATTERN.matcher(format);