Add an extra headless check to fix occational errors (#945)

* Add an extra headless check

* Update GeyserStandaloneBootstrap.java

* Rename checkHeadless to isHeadless
This commit is contained in:
rtm516 2020-07-14 00:20:56 +01:00 committed by GitHub
parent e7657c7d07
commit 0a14e3c441
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();