3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 19:10:09 +01:00

fixed bug in jvm checker (#4845)

Dieser Commit ist enthalten in:
Jake Potrebic 2020-12-04 19:58:24 -08:00 committet von GitHub
Ursprung f15abda562
Commit 684b6ea40b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -4,36 +4,35 @@ 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
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..afe07487b1e7337293f7147619a6f10fcdef9d0e
index 0000000000000000000000000000000000000000..c6ea429819c07e7f4bc257cad73463a030767825
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java
@@ -0,0 +1,49 @@
+package com.destroystokyo.paper.util;
+++ 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");
+ 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 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 int endIndex = dotIndex == -1 ? javaVersion.length() : dotIndex;
+ final String version = javaVersion.substring(0, endIndex);
+
+ 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 {}", version, e);
+ LogManager.getLogger().warn("Failed to determine Java version; Could not parse {} from {}", version, javaVersion, e);
+ return -1;
+ }
+ }
@ -60,15 +59,22 @@ index 0000000000000000000000000000000000000000..afe07487b1e7337293f7147619a6f10f
+ }
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 0108a1a68572df562349688e93f8134cb14d6116..12d781f4ae6a46d0885972035870d5b5b62f5b8b 100644
index 0108a1a68572df562349688e93f8134cb14d6116..172fc9ef9c0d3444eb99f750a17d42f130d94f73 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<TickTas
@@ -69,6 +69,7 @@ import org.bukkit.craftbukkit.Main;
import org.bukkit.event.server.ServerLoadEvent;
// CraftBukkit end
import co.aikar.timings.MinecraftTimings; // Paper
+import io.papermc.paper.util.PaperJvmChecker; // Paper
import org.spigotmc.SlackActivityAccountant; // Spigot
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable {
@@ -950,6 +951,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
LOGGER.info("Done ({})! For help, type \"help\"", doneTime);
// Paper end
+ com.destroystokyo.paper.util.PaperJvmChecker.checkJvm(); // Paper jvm version nag
+
+ PaperJvmChecker.checkJvm(); // Paper jvm version nag
org.spigotmc.WatchdogThread.tick(); // Paper
org.spigotmc.WatchdogThread.hasStarted = true; // Paper
Arrays.fill( recentTps, 20 );