Enable Multi-Release plugin jar support

Fixes #4841
This commit is contained in:
Kyle Wood 2020-12-04 15:57:46 -08:00
parent 31a6e3f898
commit f15abda562
No known key found for this signature in database
GPG key ID: D74E80413907E2D3
2 changed files with 61 additions and 38 deletions

View file

@ -0,0 +1,30 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kyle Wood <demonwav@gmail.com>
Date: Fri, 4 Dec 2020 15:53:19 -0800
Subject: [PATCH] Enable multi-release plugin jars
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index 62f7a6817da079513f471e36cd79739d36a36d86..7760be3e34fa20825faf145d9fb5b2855c1a4602 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -56,7 +56,18 @@ public final class PluginClassLoader extends URLClassLoader { // Spigot
this.description = description;
this.dataFolder = dataFolder;
this.file = file;
- this.jar = new JarFile(file);
+ // Paper - enable multi-release jars for Java 9+
+ JarFile jarFile;
+ try {
+ final java.lang.reflect.Method runtimeVersionMethod = JarFile.class.getMethod("runtimeVersion");
+ final Object runtimeVersion = runtimeVersionMethod.invoke(null);
+ @SuppressWarnings("JavaReflectionMemberAccess") final java.lang.reflect.Constructor<JarFile> constructor = JarFile.class.getConstructor(File.class, boolean.class, int.class, runtimeVersion.getClass());
+ jarFile = constructor.newInstance(file, true, java.util.zip.ZipFile.OPEN_READ, runtimeVersion);
+ } catch (Exception ignored) {
+ jarFile = new JarFile(file);
+ }
+ this.jar = jarFile;
+ // Paper end
this.manifest = jar.getManifest();
this.url = file.toURI().toURL();

View file

@ -6,64 +6,57 @@ 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/com/destroystokyo/paper/util/PaperJvmChecker.java b/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..023123d52fbb458e6ee2d38e42c9651a5c7be728 index 0000000000000000000000000000000000000000..afe07487b1e7337293f7147619a6f10fcdef9d0e
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java +++ b/src/main/java/com/destroystokyo/paper/util/PaperJvmChecker.java
@@ -0,0 +1,56 @@ @@ -0,0 +1,49 @@
+package com.destroystokyo.paper.util; +package com.destroystokyo.paper.util;
+ +
+import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Logger;
+ +
+public final class PaperJvmChecker { +public class PaperJvmChecker {
+ +
+ private PaperJvmChecker() {} + private static int getJvmVersion() {
+ + String javaVersion = System.getProperty("java.version");
+ public static void checkJvm() { + int dotIndex = javaVersion.indexOf('.');
+ final Logger logger = LogManager.getLogger();
+
+ final String javaVersion = System.getProperty("java.version");
+ final int dotIndex = javaVersion.indexOf('.');
+ +
+ if (javaVersion.startsWith("1.")) { + if (javaVersion.startsWith("1.")) {
+ // definitely old + // For Java 8 and below, trim off the 1. prefix
+ PaperJvmChecker.printWarning(javaVersion, logger); + javaVersion = javaVersion.substring(2);
+ return; + dotIndex = javaVersion.indexOf('.');
+ } + }
+ +
+ final int endIndex = dotIndex == -1 ? javaVersion.length() : dotIndex; + final int endIndex = dotIndex == -1 ? javaVersion.length() : dotIndex;
+ final String version = javaVersion.substring(0, endIndex); + final String version = javaVersion.substring(0, endIndex);
+ +
+ final int javaVersionNum;
+ try { + try {
+ javaVersionNum = Integer.parseInt(version); + return Integer.parseInt(version);
+ } catch (final NumberFormatException e) { + } catch (final NumberFormatException e) {
+ logger.warn("Failed to determine Java version; Could not parse {}", version, e); + LogManager.getLogger().warn("Failed to determine Java version; Could not parse {}", version, e);
+ PaperJvmChecker.printWarning(javaVersion, logger); + return -1;
+ return;
+ }
+
+ if (javaVersionNum < 11) {
+ PaperJvmChecker.printWarning(javaVersion, logger);
+ } + }
+ } + }
+ +
+ private static void printWarning(final String version, final Logger logger) { + public static void checkJvm() {
+ logger.warn("************************************************************"); + if (getJvmVersion() < 11) {
+ logger.warn("* WARNING - YOU ARE RUNNING AN OUTDATED VERSION OF JAVA."); + final Logger logger = LogManager.getLogger();
+ logger.warn("* PAPER WILL STOP BEING COMPATIBLE WITH THIS VERSION OF"); + logger.warn("************************************************************");
+ logger.warn("* JAVA WHEN MINECRAFT 1.17 IS RELEASED."); + logger.warn("* WARNING - YOU ARE RUNNING AN OUTDATED VERSION OF JAVA.");
+ logger.warn("*"); + logger.warn("* PAPER WILL STOP BEING COMPATIBLE WITH THIS VERSION OF");
+ logger.warn("* Please update the version of Java you use to run Paper"); + logger.warn("* JAVA WHEN MINECRAFT 1.17 IS RELEASED.");
+ logger.warn("* to at least Java 11. When Paper for Minecraft 1.17 is"); + logger.warn("*");
+ logger.warn("* released support for versions of Java before 11 will"); + logger.warn("* Please update the version of Java you use to run Paper");
+ logger.warn("* be dropped."); + logger.warn("* to at least Java 11. When Paper for Minecraft 1.17 is");
+ logger.warn("*"); + logger.warn("* released support for versions of Java before 11 will");
+ logger.warn("* Current Java version: " + version); + logger.warn("* be dropped.");
+ logger.warn("*"); + logger.warn("*");
+ logger.warn("* Check this forum post for more information: "); + logger.warn("* Current Java version: {}", System.getProperty("java.version"));
+ logger.warn("* https://papermc.io/java11"); + logger.warn("*");
+ 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 diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java