3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00
Paper/patches/server-remapped/0610-Add-warning-for-servers-not-running-on-Java-16.patch
Mariell Hoversholm a207d14a0e
Rename all patches to correct numbering scheme
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
2021-06-11 15:46:44 +02:00

81 Zeilen
3.8 KiB
Diff

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 16
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..fdf3ff8894e5e202229d1be52fe3c92ea039ef15
--- /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() < 16) {
+ 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 16. When Paper for Minecraft 1.17 is");
+ logger.warn("* released support for versions of Java before 16 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/java16");
+ logger.warn("************************************************************");
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 954dce690852da87a37e7797c6f9f549242e511a..c83f2636ae93d92381e019d5b13ac82c5a1d30bf 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -180,6 +180,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 ReentrantBlockableEventLoop<TickTask> implements SnooperPopulator, CommandSource, AutoCloseable {
@@ -1075,6 +1076,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
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 );