From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Kyle Wood 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/com/destroystokyo/paper/util/PaperJvmChecker.java b/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java new file mode 100644 index 0000000000000000000000000000000000000000..afe07487b1e7337293f7147619a6f10fcdef9d0e --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java @@ -0,0 +1,49 @@ +package com.destroystokyo.paper.util; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class PaperJvmChecker { + + private static int getJvmVersion() { + String javaVersion = System.getProperty("java.version"); + int dotIndex = javaVersion.indexOf('.'); + + if (javaVersion.startsWith("1.")) { + // For Java 8 and below, trim off the 1. prefix + javaVersion = javaVersion.substring(2); + dotIndex = javaVersion.indexOf('.'); + } + + final int endIndex = dotIndex == -1 ? javaVersion.length() : dotIndex; + final String version = javaVersion.substring(0, endIndex); + + try { + return Integer.parseInt(version); + } catch (final NumberFormatException e) { + LogManager.getLogger().warn("Failed to determine Java version; Could not parse {}", version, 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 0108a1a68572df562349688e93f8134cb14d6116..12d781f4ae6a46d0885972035870d5b5b62f5b8b 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -950,6 +950,8 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant