Compare commits

..

No commits in common. "Improved-Server-Flags" and "master" have entirely different histories.

3 changed files with 18 additions and 82 deletions

View File

@ -370,32 +370,17 @@ public class Server {
private String getJavaCommand() {
ServerLauncherController controller = ServerLauncherController.getInstance();
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 <p>The version to require</p>
* @return <p>True if the server version is at least the given version</p>
*/
private boolean versionAtLeast(String version) {
if (serverVersion.toLowerCase().contains("latest")) {
return true;
return controller.getJavaCommand();
} else if (serverVersion.contains(".") && serverVersion.split("\\.").length >= 2) {
try {
return Integer.parseInt(serverVersion.split("\\.")[0]) >=
Integer.parseInt(version.split("\\.")[0]) &&
Integer.parseInt(serverVersion.split("\\.")[1]) >=
Integer.parseInt(version.split("\\.")[1]);
if (Integer.parseInt(serverVersion.split("\\.")[1]) >= 17) {
return controller.getJavaCommand();
}
} catch (NumberFormatException ignored) {
}
}
return false;
return controller.getOldJavaCommand();
}
/**
@ -404,7 +389,17 @@ public class Server {
* @throws IOException <p>If the process cannot be started</p>
*/
private void startServerProcess() throws IOException {
ProcessBuilder builder = new ProcessBuilder(generateServerProcessArguments());
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");
builder.directory(new File(this.path));
builder.redirectErrorStream(true);
this.process = builder.start();
@ -422,64 +417,6 @@ public class Server {
}, 10, 500, TimeUnit.MILLISECONDS);
}
/**
* Generates the process arguments required for starting this Minecraft server
*
* @return <p>The process arguments required for starting this Minecraft server</p>
*/
private List<String> generateServerProcessArguments() {
//Decide the path of the .jar file to be executed
String serverPath;
if (type.getName().equalsIgnoreCase("Custom")) {
serverPath = this.path + File.separator + serverVersion;
} else {
serverPath = jarDirectory + this.type.getName() + serverVersion + ".jar";
}
List<String> processArguments = new ArrayList<>(20);
processArguments.add(getJavaCommand());
processArguments.add("-Xmx" + this.maxRam);
processArguments.add("-Xms512M");
if (versionAtLeast("1.8") && !getType().isProxy()) {
addGarbageCollectorFlags(processArguments);
}
processArguments.add("-Djline.terminal=jline.UnsupportedTerminal");
processArguments.add("-Dcom.mojang.eula.agree=true");
processArguments.add("-jar");
processArguments.add(serverPath);
processArguments.add("nogui");
return processArguments;
}
/**
* Adds garbage collector flags to the server process arguments to improve performance
*
* @param processArguments <p>The process arguments to add the flags to</p>
*/
private void addGarbageCollectorFlags(List<String> processArguments) {
processArguments.add("-XX:+UseG1GC");
processArguments.add("-XX:+ParallelRefProcEnabled");
processArguments.add("-XX:MaxGCPauseMillis=200");
processArguments.add("-XX:+UnlockExperimentalVMOptions");
processArguments.add("-XX:+DisableExplicitGC");
processArguments.add("-XX:+AlwaysPreTouch");
boolean excessiveRam = Integer.parseInt(this.maxRam.substring(0, this.maxRam.length() - 1)) > 11;
processArguments.add("-XX:G1NewSizePercent=" + (excessiveRam ? 40 : 30));
processArguments.add("-XX:G1MaxNewSizePercent=" + (excessiveRam ? 50 : 40));
processArguments.add("-XX:G1HeapRegionSize=" + (excessiveRam ? "16M" : "8M"));
processArguments.add("-XX:G1ReservePercent=" + (excessiveRam ? 15 : 20));
processArguments.add("-XX:G1HeapWastePercent=5");
processArguments.add("-XX:G1MixedGCCountTarget=4");
processArguments.add("-XX:InitiatingHeapOccupancyPercent=" + (excessiveRam ? 20 : 15));
processArguments.add("-XX:G1MixedGCLiveThresholdPercent=90");
processArguments.add("-XX:G1RSetUpdatingPauseTimePercent=5");
processArguments.add("-XX:SurvivorRatio=32");
processArguments.add("-XX:+PerfDisableSharedMem");
processArguments.add("-XX:MaxTenuringThreshold=1");
processArguments.add("-Dusing.aikars.flags=https://mcflags.emc.gs");
processArguments.add("-Daikars.new.flags=true");
}
/**
* Updates a single console with process output
*
@ -643,5 +580,4 @@ public class Server {
this.getMaxRam()
);
}
}

View File

@ -16,7 +16,7 @@ public class ServerHandler {
* Available ram sizes. For ServerLauncherGUI combo
*/
private static final String[] ramList = {"512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G",
"11G", "12G", "13G", "14G", "15G", "16G", "17G", "18G", "19G", "20G", "21G", "22G", "23G", "24G"};
"11G", "12G", "13G", "14G", "15G", "16G"};
private static boolean stoppingServers = false;
private static final ServerLauncherGUI gui = Main.getController().getGUI();

View File

@ -28,7 +28,7 @@ public final class BackupUtil {
private static boolean backupRunning = false;
private BackupUtil() {
}
/**