mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-25 19:42:53 +08:00
Update Grasscutter.java
This commit is contained in:
parent
6fc4065fa0
commit
08c01ab15d
@ -6,6 +6,7 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOError;
|
import java.io.IOError;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import emu.grasscutter.command.CommandMap;
|
import emu.grasscutter.command.CommandMap;
|
||||||
import emu.grasscutter.plugin.PluginManager;
|
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 Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
private static final File configFile = new File("./config.json");
|
private static final File configFile = new File("./config.json");
|
||||||
|
|
||||||
private static int day; // Current day of week
|
private static int day; // Current day of week
|
||||||
|
|
||||||
private static DispatchServer dispatchServer;
|
private static DispatchServer dispatchServer;
|
||||||
private static GameServer gameServer;
|
private static GameServer gameServer;
|
||||||
private static PluginManager pluginManager;
|
private static PluginManager pluginManager;
|
||||||
|
|
||||||
public static final Reflections reflector = new Reflections("emu.grasscutter");
|
public static final Reflections reflector = new Reflections("emu.grasscutter");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Declare logback configuration.
|
// Declare logback configuration.
|
||||||
System.setProperty("logback.configurationFile", "src/main/resources/logback.xml");
|
System.setProperty("logback.configurationFile", "src/main/resources/logback.xml");
|
||||||
|
|
||||||
// Load server configuration.
|
// Load server configuration.
|
||||||
Grasscutter.loadConfig();
|
Grasscutter.loadConfig();
|
||||||
|
|
||||||
// Load Language
|
// Load Language
|
||||||
Grasscutter.loadLanguage();
|
Grasscutter.loadLanguage();
|
||||||
|
|
||||||
// Check server structure.
|
// Check server structure.
|
||||||
Utils.startupCheck();
|
Utils.startupCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Crypto.loadKeys();
|
Crypto.loadKeys();
|
||||||
|
|
||||||
for (String arg : args) {
|
for (String arg : args) {
|
||||||
switch (arg.toLowerCase()) {
|
switch (arg.toLowerCase()) {
|
||||||
case "-handbook" -> {
|
case "-handbook" -> {
|
||||||
@ -79,27 +80,27 @@ public final class Grasscutter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize server.
|
// Initialize server.
|
||||||
Grasscutter.getLogger().info(language.Starting_Grasscutter);
|
Grasscutter.getLogger().info(language.Starting_Grasscutter);
|
||||||
|
|
||||||
// Load all resources.
|
// Load all resources.
|
||||||
Grasscutter.updateDayOfWeek();
|
Grasscutter.updateDayOfWeek();
|
||||||
ResourceLoader.loadAll();
|
ResourceLoader.loadAll();
|
||||||
ScriptLoader.init();
|
ScriptLoader.init();
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
DatabaseManager.initialize();
|
DatabaseManager.initialize();
|
||||||
|
|
||||||
// Create plugin manager instance.
|
// Create plugin manager instance.
|
||||||
pluginManager = new PluginManager();
|
pluginManager = new PluginManager();
|
||||||
|
|
||||||
// Create server instances.
|
// Create server instances.
|
||||||
dispatchServer = new DispatchServer();
|
dispatchServer = new DispatchServer();
|
||||||
gameServer = new GameServer(new InetSocketAddress(getConfig().getGameServerOptions().Ip, getConfig().getGameServerOptions().Port));
|
gameServer = new GameServer(new InetSocketAddress(getConfig().getGameServerOptions().Ip, getConfig().getGameServerOptions().Port));
|
||||||
// Create a server hook instance with both servers.
|
// Create a server hook instance with both servers.
|
||||||
new ServerHook(gameServer, dispatchServer);
|
new ServerHook(gameServer, dispatchServer);
|
||||||
|
|
||||||
// Start servers.
|
// Start servers.
|
||||||
if (getConfig().RunMode == ServerRunMode.HYBRID) {
|
if (getConfig().RunMode == ServerRunMode.HYBRID) {
|
||||||
dispatchServer.start();
|
dispatchServer.start();
|
||||||
@ -114,7 +115,7 @@ public final class Grasscutter {
|
|||||||
getLogger().error(language.Shutting_down);
|
getLogger().error(language.Shutting_down);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable all plugins.
|
// Enable all plugins.
|
||||||
pluginManager.enablePlugins();
|
pluginManager.enablePlugins();
|
||||||
|
|
||||||
@ -144,12 +145,12 @@ public final class Grasscutter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void loadLanguage() {
|
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);
|
language = gson.fromJson(file, Language.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Grasscutter.language = new Language();
|
Grasscutter.language = new Language();
|
||||||
Grasscutter.cn_language = new CNLanguage();
|
Grasscutter.cn_language = new CNLanguage();
|
||||||
Grasscutter.config.Language = "en_us";
|
Grasscutter.config.LocaleLanguage = Locale.getDefault();
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -161,19 +162,26 @@ public final class Grasscutter {
|
|||||||
} catch (Exception ee) {
|
} catch (Exception ee) {
|
||||||
Grasscutter.getLogger().error("Unable to create language folder.");
|
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));
|
file.write(gson.toJson(language));
|
||||||
} catch (Exception ee) {
|
} catch (Exception ee) {
|
||||||
Grasscutter.getLogger().error("Unable to create language file.");
|
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));
|
file.write(gson.toJson(cn_language));
|
||||||
} catch (Exception ee) {
|
} 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() {
|
public static void saveConfig() {
|
||||||
try (FileWriter file = new FileWriter(configFile)) {
|
try (FileWriter file = new FileWriter(configFile)) {
|
||||||
file.write(gson.toJson(config));
|
file.write(gson.toJson(config));
|
||||||
@ -181,7 +189,7 @@ public final class Grasscutter {
|
|||||||
Grasscutter.getLogger().error("Unable to save config file.");
|
Grasscutter.getLogger().error("Unable to save config file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startConsole() {
|
public static void startConsole() {
|
||||||
// Console should not start in dispatch only mode.
|
// Console should not start in dispatch only mode.
|
||||||
if (getConfig().RunMode == ServerRunMode.DISPATCH_ONLY) {
|
if (getConfig().RunMode == ServerRunMode.DISPATCH_ONLY) {
|
||||||
@ -263,11 +271,11 @@ public final class Grasscutter {
|
|||||||
public static GameServer getGameServer() {
|
public static GameServer getGameServer() {
|
||||||
return gameServer;
|
return gameServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PluginManager getPluginManager() {
|
public static PluginManager getPluginManager() {
|
||||||
return pluginManager;
|
return pluginManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateDayOfWeek() {
|
public static void updateDayOfWeek() {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
day = calendar.get(Calendar.DAY_OF_WEEK);
|
day = calendar.get(Calendar.DAY_OF_WEEK);
|
||||||
@ -276,11 +284,11 @@ public final class Grasscutter {
|
|||||||
public static int getCurrentDayOfWeek() {
|
public static int getCurrentDayOfWeek() {
|
||||||
return day;
|
return day;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ServerRunMode {
|
public enum ServerRunMode {
|
||||||
HYBRID, DISPATCH_ONLY, GAME_ONLY
|
HYBRID, DISPATCH_ONLY, GAME_ONLY
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ServerDebugMode {
|
public enum ServerDebugMode {
|
||||||
ALL, MISSING, NONE
|
ALL, MISSING, NONE
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user