diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index ec8063d4e..10ebeb7f1 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -6,6 +6,7 @@ import java.io.FileWriter; import java.io.IOError; import java.net.InetSocketAddress; import java.util.Calendar; +import java.util.Locale; import emu.grasscutter.command.CommandMap; import emu.grasscutter.plugin.PluginManager; @@ -43,32 +44,32 @@ public final class Grasscutter { private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private static final File configFile = new File("./config.json"); - + private static int day; // Current day of week - + private static DispatchServer dispatchServer; private static GameServer gameServer; private static PluginManager pluginManager; - + public static final Reflections reflector = new Reflections("emu.grasscutter"); - + static { // Declare logback configuration. System.setProperty("logback.configurationFile", "src/main/resources/logback.xml"); - + // Load server configuration. Grasscutter.loadConfig(); // Load Language Grasscutter.loadLanguage(); - + // Check server structure. Utils.startupCheck(); } - + public static void main(String[] args) throws Exception { Crypto.loadKeys(); - + for (String arg : args) { switch (arg.toLowerCase()) { case "-handbook" -> { @@ -79,27 +80,27 @@ public final class Grasscutter { } } } - + // Initialize server. Grasscutter.getLogger().info(language.Starting_Grasscutter); - + // Load all resources. Grasscutter.updateDayOfWeek(); ResourceLoader.loadAll(); ScriptLoader.init(); - + // Database DatabaseManager.initialize(); // Create plugin manager instance. pluginManager = new PluginManager(); - + // Create server instances. dispatchServer = new DispatchServer(); gameServer = new GameServer(new InetSocketAddress(getConfig().getGameServerOptions().Ip, getConfig().getGameServerOptions().Port)); // Create a server hook instance with both servers. new ServerHook(gameServer, dispatchServer); - + // Start servers. if (getConfig().RunMode == ServerRunMode.HYBRID) { dispatchServer.start(); @@ -114,7 +115,7 @@ public final class Grasscutter { getLogger().error(language.Shutting_down); System.exit(1); } - + // Enable all plugins. pluginManager.enablePlugins(); @@ -144,12 +145,12 @@ public final class Grasscutter { } public static void loadLanguage() { - try (FileReader file = new FileReader(String.format("%s%s.json", getConfig().LANGUAGE_FOLDER, Grasscutter.config.Language))) { + try (FileReader file = new FileReader(String.format("%s%s.json", getConfig().LANGUAGE_FOLDER, Grasscutter.config.LocaleLanguage))) { language = gson.fromJson(file, Language.class); } catch (Exception e) { Grasscutter.language = new Language(); Grasscutter.cn_language = new CNLanguage(); - Grasscutter.config.Language = "en_us"; + Grasscutter.config.LocaleLanguage = Locale.getDefault(); saveConfig(); try { @@ -161,19 +162,26 @@ public final class Grasscutter { } catch (Exception ee) { Grasscutter.getLogger().error("Unable to create language folder."); } - try (FileWriter file = new FileWriter("./languages/en_us.json")) { + try (FileWriter file = new FileWriter("./languages/" + Locale.US + ".json")) { file.write(gson.toJson(language)); } catch (Exception ee) { Grasscutter.getLogger().error("Unable to create language file."); } - try (FileWriter file = new FileWriter("./languages/zh_cn.json")) { + try (FileWriter file = new FileWriter("./languages/" + Locale.SIMPLIFIED_CHINESE + ".json")) { file.write(gson.toJson(cn_language)); } catch (Exception ee) { - Grasscutter.getLogger().error("无法创建中文语言文件。"); + Grasscutter.getLogger().error("无法创建简体中文语言文件。"); + } + + // try again + try (FileReader file = new FileReader(String.format("%s%s.json", getConfig().LANGUAGE_FOLDER, Grasscutter.config.LocaleLanguage))) { + language = gson.fromJson(file, Language.class); + } catch (Exception ee) { + Grasscutter.getLogger().error("Unable to load " + Grasscutter.config.LocaleLanguage + ".json"); } } } - + public static void saveConfig() { try (FileWriter file = new FileWriter(configFile)) { file.write(gson.toJson(config)); @@ -181,7 +189,7 @@ public final class Grasscutter { Grasscutter.getLogger().error("Unable to save config file."); } } - + public static void startConsole() { // Console should not start in dispatch only mode. if (getConfig().RunMode == ServerRunMode.DISPATCH_ONLY) { @@ -263,11 +271,11 @@ public final class Grasscutter { public static GameServer getGameServer() { return gameServer; } - + public static PluginManager getPluginManager() { return pluginManager; } - + public static void updateDayOfWeek() { Calendar calendar = Calendar.getInstance(); day = calendar.get(Calendar.DAY_OF_WEEK); @@ -276,11 +284,11 @@ public final class Grasscutter { public static int getCurrentDayOfWeek() { return day; } - + public enum ServerRunMode { HYBRID, DISPATCH_ONLY, GAME_ONLY } - + public enum ServerDebugMode { ALL, MISSING, NONE }