From 5b67c78785f934c8ff213656c9b619e35bd9da7e Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Thu, 16 Jun 2022 17:14:47 -0400 Subject: [PATCH] Allow Minecraft locales to be loaded even if offline --- .../geysermc/geyser/text/MinecraftLocale.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java b/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java index 57749f29e..93150942c 100644 --- a/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java +++ b/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java @@ -126,14 +126,20 @@ public class MinecraftLocale { // Check the locale isn't already loaded if (!ASSET_MAP.containsKey("minecraft/lang/" + locale + ".json") && !locale.equals("en_us")) { - GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.invalid", locale)); + if (loadLocale(locale)) { + GeyserImpl.getInstance().getLogger().debug("Loaded locale locally while not being in asset map: " + locale); + } else { + GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.invalid", locale)); + } return; } GeyserImpl.getInstance().getLogger().debug("Downloading and loading locale: " + locale); downloadLocale(locale); - loadLocale(locale); + if (!loadLocale(locale)) { + GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.missing", locale)); + } } /** @@ -199,7 +205,7 @@ public class MinecraftLocale { * * @param locale Locale to load */ - private static void loadLocale(String locale) { + private static boolean loadLocale(String locale) { File localeFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/" + locale + ".json").toFile(); // Load the locale @@ -242,8 +248,9 @@ public class MinecraftLocale { } catch (IOException e) { throw new AssertionError(GeyserLocale.getLocaleStringLog("geyser.locale.fail.file", locale, e.getMessage())); } + return true; } else { - GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.missing", locale)); + return false; } } @@ -300,9 +307,9 @@ public class MinecraftLocale { * @return Translated string or the original message if it was not found in the given locale */ public static String getLocaleString(String messageText, String locale) { - Map localeStrings = MinecraftLocale.LOCALE_MAPPINGS.get(locale.toLowerCase()); + Map localeStrings = LOCALE_MAPPINGS.get(locale.toLowerCase(Locale.ROOT)); if (localeStrings == null) { - localeStrings = MinecraftLocale.LOCALE_MAPPINGS.get(GeyserLocale.getDefaultLocale()); + localeStrings = LOCALE_MAPPINGS.get(GeyserLocale.getDefaultLocale()); if (localeStrings == null) { // Don't cause a NPE if the locale is STILL missing GeyserImpl.getInstance().getLogger().debug("MISSING DEFAULT LOCALE: " + GeyserLocale.getDefaultLocale());