2022-10-22 18:57:21 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Noah van der Aa <ndvdaa@gmail.com>
Date: Sat, 22 Oct 2022 14:47:45 +0200
Subject: [PATCH] Detect headless JREs
Crashes caused by the missing AWT dependency come up in the support channels fairly often.
This patch detects the missing dependency and stops the server with a clear error message,
containing a link to instructions on how to install a non-headless JRE.
diff --git a/src/main/java/io/papermc/paper/util/ServerEnvironment.java b/src/main/java/io/papermc/paper/util/ServerEnvironment.java
2022-11-12 13:09:54 +01:00
index 6bd0afddbcc461149dfe9a5c7a86fff6ea13a5f1..148d233f4f5278ff39eacdaa0f4f0e7d73be936a 100644
2022-10-22 18:57:21 +02:00
--- a/src/main/java/io/papermc/paper/util/ServerEnvironment.java
+++ b/src/main/java/io/papermc/paper/util/ServerEnvironment.java
@@ -37,4 +37,14 @@ public class ServerEnvironment {
public static boolean userIsRootOrAdmin() {
return RUNNING_AS_ROOT_OR_ADMIN;
}
+
2022-11-12 13:09:54 +01:00
+ public static String awtDependencyCheck() {
2022-10-22 18:57:21 +02:00
+ try {
+ new java.awt.Color(0);
+ } catch (UnsatisfiedLinkError e) {
2022-11-12 13:09:54 +01:00
+ return e.getClass().getName() + ": " + e.getMessage();
2022-10-22 18:57:21 +02:00
+ }
+
2022-11-12 13:09:54 +01:00
+ return null;
2022-10-22 18:57:21 +02:00
+ }
}
diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java
2024-01-21 19:37:09 +01:00
index b0a0909fa9501dfacfbe70dc4118062d1154bd15..19009f0c1d572eebad6cce93f8cf56ca820fc33f 100644
2022-10-22 18:57:21 +02:00
--- a/src/main/java/net/minecraft/server/Main.java
+++ b/src/main/java/net/minecraft/server/Main.java
2023-12-06 17:21:56 +01:00
@@ -175,6 +175,18 @@ public class Main {
2022-10-22 18:57:21 +02:00
return;
}
2024-01-18 15:56:25 +01:00
+ // Paper start - Detect headless JRE
2022-11-12 13:09:54 +01:00
+ String awtException = io.papermc.paper.util.ServerEnvironment.awtDependencyCheck();
+ if (awtException != null) {
2022-10-22 18:57:21 +02:00
+ Main.LOGGER.error("You are using a headless JRE distribution.");
+ Main.LOGGER.error("This distribution is missing certain graphic libraries that the Minecraft server needs to function.");
+ Main.LOGGER.error("For instructions on how to install the non-headless JRE, see https://docs.papermc.io/misc/java-install");
2022-11-12 13:09:54 +01:00
+ Main.LOGGER.error("");
+ Main.LOGGER.error(awtException);
2022-10-22 18:57:21 +02:00
+ return;
+ }
2024-01-18 15:56:25 +01:00
+ // Paper end - Detect headless JRE
2022-10-22 18:57:21 +02:00
+
org.spigotmc.SpigotConfig.disabledAdvancements = spigotConfiguration.getStringList("advancements.disabled"); // Paper - fix SPIGOT-5885, must be set early in init
// Paper start - fix SPIGOT-5824
File file;