Adds various fixes to make the two java versions work as expected
Makes it possible to load a controller without generating a GUI, for better testing Makes sure not to try and parse empty profile lines Saves controller settings in a more readable and appendable format Adds code for using the correct java version for the occasion Adds a new function for writing to files
This commit is contained in:
@ -2,7 +2,7 @@ package net.knarcraft.minecraftserverlauncher.server;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Controller;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||
|
||||
@ -147,6 +147,7 @@ public class Server {
|
||||
|
||||
/**
|
||||
* Kills all server processes
|
||||
*
|
||||
* @throws InterruptedException <p>If interrupted waiting for any of the servers to stop</p>
|
||||
*/
|
||||
private static void killServers() throws InterruptedException {
|
||||
@ -158,6 +159,7 @@ public class Server {
|
||||
|
||||
/**
|
||||
* Kills the given server after waiting 30 seconds for it to terminate normally
|
||||
*
|
||||
* @param server <p>The server to kill</p>
|
||||
* @throws InterruptedException <p>If interrupted waiting for the server to stop</p>
|
||||
*/
|
||||
@ -174,7 +176,7 @@ public class Server {
|
||||
* Runs all enabled servers with their settings
|
||||
*/
|
||||
public static void startServers() {
|
||||
Controller controller = Main.getController();
|
||||
ServerLauncherController controller = Main.getController();
|
||||
controller.getGUI().setStatus("Starting servers");
|
||||
int serverNum = 0;
|
||||
for (Collection collection : controller.getCurrentProfile().getCollections()) {
|
||||
@ -429,6 +431,23 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the correct java command to use for the selected server version
|
||||
*
|
||||
* @return <p>The java version to run</p>
|
||||
*/
|
||||
private String getJavaCommand() {
|
||||
ServerLauncherController controller = ServerLauncherController.getInstance();
|
||||
if (serverVersion.toLowerCase().contains("latest")) {
|
||||
return controller.getJavaCommand();
|
||||
} else if (serverVersion.contains(".") && serverVersion.split("\\.").length >= 2 &&
|
||||
Integer.parseInt(serverVersion.split("\\.")[1]) >= 17) {
|
||||
return controller.getJavaCommand();
|
||||
} else {
|
||||
return controller.getOldJavaCommand();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the process running this server
|
||||
*
|
||||
@ -443,7 +462,7 @@ public class Server {
|
||||
} else {
|
||||
serverPath = jarDirectory + this.type.getName() + serverVersion + ".jar";
|
||||
}
|
||||
builder = new ProcessBuilder("java", "-Xmx" + this.maxRam, "-Xms512M",
|
||||
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));
|
||||
@ -482,7 +501,7 @@ public class Server {
|
||||
/**
|
||||
* Looks for strings implying a player has joined or left, and updates the appropriate lists
|
||||
*
|
||||
* @param text <p>The text to search</p>
|
||||
* @param text <p>The text to search</p>
|
||||
*/
|
||||
private void updatePlayerList(String text) {
|
||||
if (!getType().isProxy()) {
|
||||
@ -532,8 +551,9 @@ public class Server {
|
||||
|
||||
/**
|
||||
* Returns the first regex capture group found in a pattern
|
||||
*
|
||||
* @param pattern <p>The regex pattern to use</p>
|
||||
* @param text <p>The string to execute the pattern on</p>
|
||||
* @param text <p>The string to execute the pattern on</p>
|
||||
* @return <p>The first capture group if a match is found. An empty string otherwise</p>
|
||||
*/
|
||||
private String getFirstRegexCaptureGroup(String pattern, String text) {
|
||||
@ -569,7 +589,7 @@ public class Server {
|
||||
* @return <p>True if nothing went wrong</p>
|
||||
*/
|
||||
private boolean initializeJarDownload() {
|
||||
Controller controller = Main.getController();
|
||||
ServerLauncherController controller = Main.getController();
|
||||
if (!controller.getDownloadAllJars()) {
|
||||
try {
|
||||
controller.getGUI().setStatus("Downloading jar...");
|
||||
|
@ -1,6 +1,17 @@
|
||||
package net.knarcraft.minecraftserverlauncher.server;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.*;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.BungeeCord;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.CraftBukkit;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Custom;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.MCPCPlus;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Paper;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Spigot;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.SpongeForge;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.SpongeVanilla;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Travertine;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Vanilla;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Waterfall;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -3,7 +3,10 @@ package net.knarcraft.minecraftserverlauncher.server;
|
||||
import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -122,8 +125,8 @@ public class ServerVersionContainer {
|
||||
if (!new File(versionFile).exists()) {
|
||||
return;
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(versionFile)))) {
|
||||
String currentData = CommonFunctions.readBufferedReader(reader);
|
||||
try {
|
||||
String currentData = CommonFunctions.readFile(versionFile);
|
||||
for (String line : currentData.split("\n")) {
|
||||
parseSaveLine(line);
|
||||
}
|
||||
@ -178,9 +181,9 @@ public class ServerVersionContainer {
|
||||
* Reads versions from a text string and updates the version map
|
||||
*
|
||||
* @param targetMap <p>The map to update</p>
|
||||
* @param data <p>The data string to parse</p>
|
||||
* @param data <p>The data string to parse</p>
|
||||
*/
|
||||
private void parseVersionsToMap(Map<String,String> targetMap, String data) {
|
||||
private void parseVersionsToMap(Map<String, String> targetMap, String data) {
|
||||
String[] versions = data.split(",");
|
||||
for (String version : versions) {
|
||||
String[] versionData = version.split("!");
|
||||
|
@ -20,8 +20,8 @@ public class SpongeVanilla extends AbstractServerType {
|
||||
private final String srcStart;
|
||||
private final String srcEnd;
|
||||
private final String downloadURLPart;
|
||||
Function<String,String> oldVersionFunction;
|
||||
BiConsumer<String,String> versionUpdateFunction;
|
||||
Function<String, String> oldVersionFunction;
|
||||
BiConsumer<String, String> versionUpdateFunction;
|
||||
final ServerVersionContainer serverVersionContainer;
|
||||
|
||||
/**
|
||||
|
@ -54,9 +54,9 @@ public class Vanilla extends AbstractServerType {
|
||||
/**
|
||||
* Downloads the latest .jar file found if necessary
|
||||
*
|
||||
* @param filePath <p>The path of the jar file to download</p>
|
||||
* @param releaseType <p>The release type used for downloading</p>
|
||||
* @param lastVersion <p>The last server version found</p>
|
||||
* @param filePath <p>The path of the jar file to download</p>
|
||||
* @param releaseType <p>The release type used for downloading</p>
|
||||
* @param lastVersion <p>The last server version found</p>
|
||||
* @param versionContainer <p>The version container to use</p>
|
||||
* @return <p>True if the jar exists and is the latest version or was downloaded</p>
|
||||
* @throws IOException <p>If the .jar cannot be downloaded</p>
|
||||
|
Reference in New Issue
Block a user