mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-16 23:34:50 +01:00
(misc:LunarCore.java) format
This commit is contained in:
@@ -26,7 +26,7 @@ import lombok.Getter;
|
|||||||
public class LunarCore {
|
public class LunarCore {
|
||||||
private static final Logger log = (Logger) LoggerFactory.getLogger(LunarCore.class);
|
private static final Logger log = (Logger) LoggerFactory.getLogger(LunarCore.class);
|
||||||
private static File configFile = new File("./config.json");
|
private static File configFile = new File("./config.json");
|
||||||
private static Config config;
|
@Getter private static Config config;
|
||||||
|
|
||||||
@Getter private static DatabaseManager accountDatabase;
|
@Getter private static DatabaseManager accountDatabase;
|
||||||
@Getter private static DatabaseManager gameDatabase;
|
@Getter private static DatabaseManager gameDatabase;
|
||||||
@@ -36,7 +36,7 @@ public class LunarCore {
|
|||||||
|
|
||||||
@Getter private static CommandManager commandManager;
|
@Getter private static CommandManager commandManager;
|
||||||
@Getter private static ServerType serverType = ServerType.BOTH;
|
@Getter private static ServerType serverType = ServerType.BOTH;
|
||||||
|
|
||||||
private static LineReaderImpl reader;
|
private static LineReaderImpl reader;
|
||||||
@Getter private static boolean usingDumbTerminal;
|
@Getter private static boolean usingDumbTerminal;
|
||||||
|
|
||||||
@@ -46,12 +46,12 @@ public class LunarCore {
|
|||||||
reader = (LineReaderImpl) LineReaderBuilder.builder()
|
reader = (LineReaderImpl) LineReaderBuilder.builder()
|
||||||
.terminal(TerminalBuilder.builder().dumb(true).build())
|
.terminal(TerminalBuilder.builder().dumb(true).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
usingDumbTerminal = Terminal.TYPE_DUMB.equals(reader.getTerminal().getType());
|
usingDumbTerminal = Terminal.TYPE_DUMB.equals(reader.getTerminal().getType());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
LunarCore.loadConfig();
|
LunarCore.loadConfig();
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ public class LunarCore {
|
|||||||
LunarCore.getLogger().info("Git hash: " + getGitHash());
|
LunarCore.getLogger().info("Git hash: " + getGitHash());
|
||||||
LunarCore.getLogger().info("Game version: " + GameConstants.VERSION);
|
LunarCore.getLogger().info("Game version: " + GameConstants.VERSION);
|
||||||
boolean generateHandbook = true;
|
boolean generateHandbook = true;
|
||||||
|
|
||||||
// Load commands
|
// Load commands
|
||||||
LunarCore.commandManager = new CommandManager();
|
LunarCore.commandManager = new CommandManager();
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ public class LunarCore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip these if we are only running the http server in dispatch mode
|
// Skip these if we are only running the http server in dispatch mode
|
||||||
if (serverType.runGame()) {
|
if (serverType.runGame()) {
|
||||||
// Load resources
|
// Load resources
|
||||||
@@ -100,19 +100,29 @@ public class LunarCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start Database(s)
|
try {
|
||||||
LunarCore.initDatabases();
|
// Start Database(s)
|
||||||
|
LunarCore.initDatabases();
|
||||||
|
} catch (Exception exception) {
|
||||||
|
LunarCore.getLogger().error("Unable to start the database(s).", exception);
|
||||||
|
}
|
||||||
|
|
||||||
// Always run http server as it is needed by for dispatch and gateserver
|
try {
|
||||||
httpServer = new HttpServer(serverType);
|
// Always run http server as it is needed by for dispatch and gateserver
|
||||||
httpServer.start();
|
httpServer = new HttpServer(serverType);
|
||||||
|
httpServer.start();
|
||||||
|
} catch (Exception exception) {
|
||||||
|
LunarCore.getLogger().error("Unable to start the HTTP server.", exception);
|
||||||
|
}
|
||||||
|
|
||||||
// Start game server
|
// Start game server
|
||||||
if (serverType.runGame()) {
|
if (serverType.runGame()) try {
|
||||||
gameServer = new GameServer(getConfig().getGameServer());
|
gameServer = new GameServer(getConfig().getGameServer());
|
||||||
gameServer.start();
|
gameServer.start();
|
||||||
|
} catch (Exception exception) {
|
||||||
|
LunarCore.getLogger().error("Unable to start the game server.", exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook into shutdown event
|
// Hook into shutdown event
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(LunarCore::onShutdown));
|
Runtime.getRuntime().addShutdownHook(new Thread(LunarCore::onShutdown));
|
||||||
|
|
||||||
@@ -120,14 +130,10 @@ public class LunarCore {
|
|||||||
LunarCore.startConsole();
|
LunarCore.startConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Config getConfig() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Logger getLogger() {
|
public static Logger getLogger() {
|
||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LineReaderImpl getLineReader() {
|
public static LineReaderImpl getLineReader() {
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
@@ -171,7 +177,7 @@ public class LunarCore {
|
|||||||
getLogger().error("Config save error");
|
getLogger().error("Config save error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Git hash
|
// Git hash
|
||||||
|
|
||||||
private static String getGitHash() {
|
private static String getGitHash() {
|
||||||
@@ -186,7 +192,7 @@ public class LunarCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Server console
|
// Server console
|
||||||
|
|
||||||
private static void startConsole() {
|
private static void startConsole() {
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -194,9 +200,9 @@ public class LunarCore {
|
|||||||
if (input == null || input.length() == 0) {
|
if (input == null || input.length() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
LunarCore.getCommandManager().invoke(null, input);
|
LunarCore.getCommandManager().invoke(null, input);
|
||||||
}
|
}
|
||||||
} catch (UserInterruptException | EndOfFileException e) {
|
} catch (UserInterruptException | EndOfFileException e) {
|
||||||
// CTRL + C / CTRL + D
|
// CTRL + C / CTRL + D
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
@@ -204,9 +210,9 @@ public class LunarCore {
|
|||||||
LunarCore.getLogger().error("Terminal error: ", e);
|
LunarCore.getLogger().error("Terminal error: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown event
|
// Shutdown event
|
||||||
|
|
||||||
private static void onShutdown() {
|
private static void onShutdown() {
|
||||||
if (gameServer != null) {
|
if (gameServer != null) {
|
||||||
gameServer.onShutdown();
|
gameServer.onShutdown();
|
||||||
@@ -222,7 +228,7 @@ public class LunarCore {
|
|||||||
|
|
||||||
private final int flags;
|
private final int flags;
|
||||||
|
|
||||||
private ServerType(int flags) {
|
ServerType(int flags) {
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user