aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0610-Add-warning-for-servers-not-running-on-Java-11.patch
blob: 42dcd22bdfd292f7ada21a1a917786cf08f2769f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kyle Wood <demonwav@gmail.com>
Date: Wed, 2 Dec 2020 21:58:45 -0800
Subject: [PATCH] Add warning for servers not running on Java 11


diff --git a/src/main/java/io/papermc/paper/util/PaperJvmChecker.java b/src/main/java/io/papermc/paper/util/PaperJvmChecker.java
new file mode 100644
index 0000000000000000000000000000000000000000..c6ea429819c07e7f4bc257cad73463a030767825
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/PaperJvmChecker.java
@@ -0,0 +1,48 @@
+package io.papermc.paper.util;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class PaperJvmChecker {
+
+    private static int getJvmVersion() {
+        String javaVersion = System.getProperty("java.version");
+        final Matcher matcher = Pattern.compile("(?:1\\.)?(\\d+)").matcher(javaVersion);
+        if (!matcher.find()) {
+            LogManager.getLogger().warn("Failed to determine Java version; Could not parse: {}", javaVersion);
+            return -1;
+        }
+
+        final String version = matcher.group(1);
+        try {
+            return Integer.parseInt(version);
+        } catch (final NumberFormatException e) {
+            LogManager.getLogger().warn("Failed to determine Java version; Could not parse {} from {}", version, javaVersion, e);
+            return -1;
+        }
+    }
+
+    public static void checkJvm() {
+        if (getJvmVersion() < 11) {
+            final Logger logger = LogManager.getLogger();
+            logger.warn("************************************************************");
+            logger.warn("* WARNING - YOU ARE RUNNING AN OUTDATED VERSION OF JAVA.");
+            logger.warn("* PAPER WILL STOP BEING COMPATIBLE WITH THIS VERSION OF");
+            logger.warn("* JAVA WHEN MINECRAFT 1.17 IS RELEASED.");
+            logger.warn("*");
+            logger.warn("* Please update the version of Java you use to run Paper");
+            logger.warn("* to at least Java 11. When Paper for Minecraft 1.17 is");
+            logger.warn("* released support for versions of Java before 11 will");
+            logger.warn("* be dropped.");
+            logger.warn("*");
+            logger.warn("* Current Java version: {}", System.getProperty("java.version"));
+            logger.warn("*");
+            logger.warn("* Check this forum post for more information: ");
+            logger.warn("*   https://papermc.io/java11");
+            logger.warn("************************************************************");
+        }
+    }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index cd1cd1d4adbe6d304fd7634fa2fe712a0874e189..6ae5dc6fe52fb172bec709d4ab80c624535b8e43 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -181,6 +181,7 @@ import org.bukkit.event.server.ServerLoadEvent;
 
 import co.aikar.timings.MinecraftTimings; // Paper
 import org.spigotmc.SlackActivityAccountant; // Spigot
+import io.papermc.paper.util.PaperJvmChecker; // Paper
 
 public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable {
 
@@ -1075,6 +1076,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
                 LOGGER.info("Done ({})! For help, type \"help\"", doneTime);
                 // Paper end
 
+                PaperJvmChecker.checkJvm(); // Paper jvm version nag
                 org.spigotmc.WatchdogThread.tick(); // Paper
                 org.spigotmc.WatchdogThread.hasStarted = true; // Paper
                 Arrays.fill( recentTps, 20 );