From 0a14e3c441aba28db12266538cdba23fa08f8fa1 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Tue, 14 Jul 2020 00:20:56 +0100 Subject: [PATCH] Add an extra headless check to fix occational errors (#945) * Add an extra headless check * Update GeyserStandaloneBootstrap.java * Rename checkHeadless to isHeadless --- .../standalone/GeyserStandaloneBootstrap.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneBootstrap.java index 5da4c37d..cf02d35f 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneBootstrap.java @@ -46,6 +46,7 @@ import org.geysermc.platform.standalone.gui.GeyserStandaloneGUI; import java.io.File; import java.io.IOException; +import java.lang.reflect.Method; import java.nio.file.Path; import java.nio.file.Paths; import java.util.UUID; @@ -60,7 +61,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap { private GeyserStandaloneGUI gui; @Getter - private boolean useGui = System.console() == null; + private boolean useGui = System.console() == null && !isHeadless(); private GeyserConnector connector; @@ -127,6 +128,21 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap { } } + /** + * Check using {@link java.awt.GraphicsEnvironment} that we are a headless client + * + * @return If the current environment is headless + */ + private boolean isHeadless() { + try { + Class graphicsEnv = Class.forName("java.awt.GraphicsEnvironment"); + Method isHeadless = graphicsEnv.getDeclaredMethod("isHeadless"); + return (boolean) isHeadless.invoke(null); + } catch (Exception ignore) { } + + return true; + } + @Override public void onDisable() { connector.shutdown();