- Fixed nogui option causing crashes or ignoring jvm arguments
- updated dependency You can now start the server like the following
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.vaporvee"
|
group = "com.vaporvee"
|
||||||
version = "1.0"
|
version = "1.1.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -13,7 +13,7 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.apache.logging.log4j:log4j-api:2.24.0")
|
implementation("org.apache.logging.log4j:log4j-api:2.24.0")
|
||||||
implementation("org.apache.logging.log4j:log4j-core:2.24.0")
|
implementation("org.apache.logging.log4j:log4j-core:2.24.0")
|
||||||
implementation("com.google.code.gson:gson:2.8.8")
|
implementation("com.google.code.gson:gson:2.8.9")
|
||||||
|
|
||||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||||
|
@@ -7,6 +7,8 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.lang.management.RuntimeMXBean;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@@ -15,7 +17,6 @@ import java.nio.file.*;
|
|||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ public class BoundlessServer {
|
|||||||
private static final String currentDir = System.getProperty("user.dir");
|
private static final String currentDir = System.getProperty("user.dir");
|
||||||
private static final String installerFileName = "installer.jar";
|
private static final String installerFileName = "installer.jar";
|
||||||
private static final String serverConfigFileName = "boundless-server.json";
|
private static final String serverConfigFileName = "boundless-server.json";
|
||||||
|
private static boolean nogui = false;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
writeJvmArgsToFile(args);
|
writeJvmArgsToFile(args);
|
||||||
@@ -54,23 +56,6 @@ public class BoundlessServer {
|
|||||||
launchServer();
|
launchServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static List<String> readJvmArgsFromFile() {
|
|
||||||
Path jvmArgsFile = Path.of(currentDir, "user_jvm_args.txt");
|
|
||||||
List<String> jvmArgs = new ArrayList<>();
|
|
||||||
|
|
||||||
try (BufferedReader reader = Files.newBufferedReader(jvmArgsFile)) {
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
jvmArgs.add(line);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("Error reading JVM arguments from file: {}", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return jvmArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLatestModpackUrl(String modpackSlug, String channel) {
|
public static String getLatestModpackUrl(String modpackSlug, String channel) {
|
||||||
String apiUrl = "https://api.modrinth.com/v2/project/" + modpackSlug + "/version";
|
String apiUrl = "https://api.modrinth.com/v2/project/" + modpackSlug + "/version";
|
||||||
|
|
||||||
@@ -107,11 +92,16 @@ public class BoundlessServer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeJvmArgsToFile(String[] jvmArgs) {
|
private static void writeJvmArgsToFile(String[] args) {
|
||||||
Path jvmArgsFile = Path.of(currentDir, "user_jvm_args.txt");
|
Path jvmArgsFile = Path.of(currentDir, "user_jvm_args.txt");
|
||||||
|
logger.warn(args);
|
||||||
try (BufferedWriter writer = Files.newBufferedWriter(jvmArgsFile)) {
|
try (BufferedWriter writer = Files.newBufferedWriter(jvmArgsFile)) {
|
||||||
for (String arg : jvmArgs) {
|
for (String arg : args) {
|
||||||
|
if (arg.equalsIgnoreCase("nogui") || arg.equalsIgnoreCase("--nogui")) {
|
||||||
|
writeJvmArgsFromRuntime();
|
||||||
|
nogui = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
writer.write(arg);
|
writer.write(arg);
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
}
|
}
|
||||||
@@ -121,6 +111,21 @@ public class BoundlessServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void writeJvmArgsFromRuntime() {
|
||||||
|
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
|
||||||
|
List<String> jvmArgs = runtimeMxBean.getInputArguments();
|
||||||
|
|
||||||
|
try (BufferedWriter writer = new BufferedWriter(new FileWriter("user_jvm_args.txt", true))) {
|
||||||
|
for (String arg : jvmArgs) {
|
||||||
|
writer.write(arg);
|
||||||
|
writer.newLine();
|
||||||
|
}
|
||||||
|
System.out.println("JVM arguments written to user_jvm_args.txt");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isServerUpdated() {
|
private static boolean isServerUpdated() {
|
||||||
Path configFilePath = Path.of(currentDir, serverConfigFileName);
|
Path configFilePath = Path.of(currentDir, serverConfigFileName);
|
||||||
if (Files.exists(configFilePath)) {
|
if (Files.exists(configFilePath)) {
|
||||||
@@ -189,7 +194,7 @@ public class BoundlessServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void executeInstaller(String[] jarArgs) {
|
private static void executeInstaller(String[] jarArgs) {
|
||||||
Process installerProcess = executeJarFile(jarArgs, false); // Use false to handle the installer output manually
|
Process installerProcess = executeJarFile(jarArgs, false);
|
||||||
if (installerProcess == null) {
|
if (installerProcess == null) {
|
||||||
logger.error("Failed to start the installer.jar process. Exiting program.");
|
logger.error("Failed to start the installer.jar process. Exiting program.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@@ -225,8 +230,6 @@ public class BoundlessServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void launchServer() {
|
private static void launchServer() {
|
||||||
List<String> jvmArgs = readJvmArgsFromFile();
|
|
||||||
|
|
||||||
String neoForgeVersion = "21.1.62";
|
String neoForgeVersion = "21.1.62";
|
||||||
String osSpecificArgs = System.getProperty("os.name").startsWith("Windows")
|
String osSpecificArgs = System.getProperty("os.name").startsWith("Windows")
|
||||||
? "@libraries/net/neoforged/neoforge/" + neoForgeVersion + "/win_args.txt"
|
? "@libraries/net/neoforged/neoforge/" + neoForgeVersion + "/win_args.txt"
|
||||||
@@ -235,17 +238,17 @@ public class BoundlessServer {
|
|||||||
logger.info("Starting Boundless Horizons Server...");
|
logger.info("Starting Boundless Horizons Server...");
|
||||||
|
|
||||||
List<String> commandArgs = new ArrayList<>();
|
List<String> commandArgs = new ArrayList<>();
|
||||||
commandArgs.addAll(jvmArgs);
|
|
||||||
commandArgs.add(osSpecificArgs);
|
commandArgs.add(osSpecificArgs);
|
||||||
|
|
||||||
String argSuffix = System.getProperty("os.name").startsWith("Windows") ? "%*" : "\"$@\"";
|
String argSuffix = System.getProperty("os.name").startsWith("Windows") ? "%*" : "\"$@\"";
|
||||||
commandArgs.add(argSuffix);
|
commandArgs.add(argSuffix);
|
||||||
|
if(nogui){
|
||||||
|
commandArgs.add("nogui");
|
||||||
|
}
|
||||||
|
|
||||||
// Start the server process with inheritIO to take over the terminal
|
|
||||||
Process serverProcess = executeJarFile(commandArgs.toArray(new String[0]), true);
|
Process serverProcess = executeJarFile(commandArgs.toArray(new String[0]), true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Wait for the server process to finish
|
|
||||||
int exitCode = serverProcess.waitFor();
|
int exitCode = serverProcess.waitFor();
|
||||||
logger.info("Server process exited with code: {}", exitCode);
|
logger.info("Server process exited with code: {}", exitCode);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -263,7 +266,7 @@ public class BoundlessServer {
|
|||||||
.directory(new File(currentDir));
|
.directory(new File(currentDir));
|
||||||
|
|
||||||
if (inheritIO) {
|
if (inheritIO) {
|
||||||
processBuilder.redirectErrorStream(true).inheritIO(); // Inherit I/O for the server
|
processBuilder.redirectErrorStream(true).inheritIO();
|
||||||
}
|
}
|
||||||
|
|
||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
|
Reference in New Issue
Block a user