mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-23 06:50:26 +01:00
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:
parent
e7657c7d07
commit
0a14e3c441
1 changed files with 17 additions and 1 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue