use of cn.nukkit.utils.LogLevel in project Nukkit by Nukkit.
the class Nukkit method main.
public static void main(String[] args) {
// prefer IPv4 to stop any weird RakNet issues.
System.setProperty("java.net.preferIPv4Stack", "true");
// Shorter title for windows 8/2012
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
if (osName.contains("windows 8") || osName.contains("2012")) {
shortTitle = true;
}
}
LogLevel logLevel = LogLevel.DEFAULT_LEVEL;
int index = -1;
boolean skip = false;
// 启动参数
for (String arg : args) {
index++;
if (skip) {
skip = false;
continue;
}
switch(arg) {
case "disable-ansi":
ANSI = false;
break;
case "--verbosity":
case "-v":
skip = true;
try {
String levelName = args[index + 1];
Set<String> levelNames = Arrays.stream(LogLevel.values()).map(level -> level.name().toLowerCase()).collect(Collectors.toSet());
if (!levelNames.contains(levelName.toLowerCase())) {
System.out.printf("'%s' is not a valid log level, using the default\n", levelName);
continue;
}
logLevel = Arrays.stream(LogLevel.values()).filter(level -> level.name().equalsIgnoreCase(levelName)).findAny().orElse(LogLevel.DEFAULT_LEVEL);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("You must enter the requested log level, using the default\n");
}
}
}
MainLogger logger = new MainLogger(DATA_PATH + "server.log", logLevel);
System.out.printf("Using log level '%s'\n", logLevel);
try {
if (ANSI) {
System.out.print((char) 0x1b + "]0;Starting Nukkit Server For Minecraft: PE" + (char) 0x07);
}
new Server(logger, PATH, DATA_PATH, PLUGIN_PATH);
} catch (Exception e) {
logger.logException(e);
}
if (ANSI) {
System.out.print((char) 0x1b + "]0;Stopping Server..." + (char) 0x07);
}
logger.info("Stopping other threads");
for (Thread thread : java.lang.Thread.getAllStackTraces().keySet()) {
if (!(thread instanceof InterruptibleThread)) {
continue;
}
logger.debug("Stopping " + thread.getClass().getSimpleName() + " thread");
if (thread.isAlive()) {
thread.interrupt();
}
}
ServerKiller killer = new ServerKiller(8);
killer.start();
logger.shutdown();
logger.interrupt();
CommandReader.getInstance().removePromptLine();
if (ANSI) {
System.out.print((char) 0x1b + "]0;Server Stopped" + (char) 0x07);
}
System.exit(0);
}
Aggregations