From 45da65f9df0d03ea973f7b969f79d077bd603103 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Sun, 8 Dec 2024 13:28:26 +0200 Subject: [PATCH] Automatically install a server on headless environments This PR makes the installer automatically install a server on headless environments without needing the `--install-server` option specified. This should reduce user confusion when they try to simply run the jar on a server --- build.gradle | 2 +- .../net/minecraftforge/installer/SimpleInstaller.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 901614e..eb1abdc 100644 --- a/build.gradle +++ b/build.gradle @@ -84,7 +84,7 @@ dependencies { testImplementation(platform('org.junit:junit-bom:5.7.2')) testImplementation('org.junit.jupiter:junit-jupiter') compileOnly 'org.jetbrains:annotations:24.1.0' - testInstallerData 'net.neoforged:neoforge:20.4.76-beta:installer' + testInstallerData 'net.neoforged:neoforge:21.4.10-beta:installer' } test { diff --git a/src/main/java/net/minecraftforge/installer/SimpleInstaller.java b/src/main/java/net/minecraftforge/installer/SimpleInstaller.java index a83def8..7ec83fd 100644 --- a/src/main/java/net/minecraftforge/installer/SimpleInstaller.java +++ b/src/main/java/net/minecraftforge/installer/SimpleInstaller.java @@ -15,6 +15,7 @@ */ package net.minecraftforge.installer; +import java.awt.GraphicsEnvironment; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -155,6 +156,13 @@ public static void main(String[] args) throws IOException, URISyntaxException { } } + if (action == null && GraphicsEnvironment.isHeadless()) { + monitor.message("No action was specified but headless environment was detected... Installing server"); + action = Actions.SERVER; + target = optionSet.valueOf(serverInstallOption); + ServerInstall.serverStarterJar = true; + } + if (action != null) { try { SimpleInstaller.headless = true;