diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/server/Server.java b/src/main/java/net/knarcraft/minecraftserverlauncher/server/Server.java index 17f1f74..445dbcb 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/server/Server.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/server/Server.java @@ -370,17 +370,32 @@ public class Server { private String getJavaCommand() { ServerLauncherController controller = ServerLauncherController.getInstance(); - if (serverVersion.toLowerCase().contains("latest")) { + if (versionAtLeast("1.17")) { return controller.getJavaCommand(); + } else { + return controller.getOldJavaCommand(); + } + } + + /** + * Checks if the current server version is at least the given version + * + * @param version
The version to require
+ * @returnTrue if the server version is at least the given version
+ */ + private boolean versionAtLeast(String version) { + if (serverVersion.toLowerCase().contains("latest")) { + return true; } else if (serverVersion.contains(".") && serverVersion.split("\\.").length >= 2) { try { - if (Integer.parseInt(serverVersion.split("\\.")[1]) >= 17) { - return controller.getJavaCommand(); - } + return Integer.parseInt(serverVersion.split("\\.")[0]) >= + Integer.parseInt(version.split("\\.")[0]) && + Integer.parseInt(serverVersion.split("\\.")[1]) >= + Integer.parseInt(version.split("\\.")[1]); } catch (NumberFormatException ignored) { } } - return controller.getOldJavaCommand(); + return false; } /** @@ -389,17 +404,7 @@ public class Server { * @throws IOExceptionIf the process cannot be started
*/ private void startServerProcess() throws IOException { - ProcessBuilder builder; - String serverPath; - //Decide the path of the .jar file to be executed - if (type.getName().equals("Custom")) { - serverPath = this.path + File.separator + serverVersion; - } else { - serverPath = jarDirectory + this.type.getName() + serverVersion + ".jar"; - } - builder = new ProcessBuilder(getJavaCommand(), "-Xmx" + this.maxRam, "-Xms512M", - "-Djline.terminal=jline.UnsupportedTerminal", "-Dcom.mojang.eula.agree=true", "-jar", serverPath, - "nogui"); + ProcessBuilder builder = new ProcessBuilder(generateServerProcessArguments()); builder.directory(new File(this.path)); builder.redirectErrorStream(true); this.process = builder.start(); @@ -417,6 +422,64 @@ public class Server { }, 10, 500, TimeUnit.MILLISECONDS); } + /** + * Generates the process arguments required for starting this Minecraft server + * + * @returnThe process arguments required for starting this Minecraft server
+ */ + private ListThe process arguments to add the flags to
+ */ + private void addGarbageCollectorFlags(List