From 08835cda4557eba52e535a5c0441b8f3b9855567 Mon Sep 17 00:00:00 2001 From: Kyle Wood <kyle@denwav.dev> Date: Fri, 4 Dec 2020 15:57:46 -0800 Subject: [PATCH] Enable Multi-Release plugin jar support Fixes #4841 --- .../Enable-multi-release-plugin-jars.patch | 30 +++++++++ ...g-for-servers-not-running-on-Java-11.patch | 65 +++++++++---------- 2 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 Spigot-API-Patches/Enable-multi-release-plugin-jars.patch diff --git a/Spigot-API-Patches/Enable-multi-release-plugin-jars.patch b/Spigot-API-Patches/Enable-multi-release-plugin-jars.patch new file mode 100644 index 0000000000..178e39bf6c --- /dev/null +++ b/Spigot-API-Patches/Enable-multi-release-plugin-jars.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Kyle Wood <kyle@denwav.dev> +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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java ++++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java +@@ -0,0 +0,0 @@ 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(); + diff --git a/Spigot-Server-Patches/Add-warning-for-servers-not-running-on-Java-11.patch b/Spigot-Server-Patches/Add-warning-for-servers-not-running-on-Java-11.patch index 1bac824d40..2fefa78596 100644 --- a/Spigot-Server-Patches/Add-warning-for-servers-not-running-on-Java-11.patch +++ b/Spigot-Server-Patches/Add-warning-for-servers-not-running-on-Java-11.patch @@ -15,55 +15,48 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + -+public final class PaperJvmChecker { ++public class PaperJvmChecker { + -+ private PaperJvmChecker() {} -+ -+ public static void checkJvm() { -+ final Logger logger = LogManager.getLogger(); -+ -+ final String javaVersion = System.getProperty("java.version"); -+ final int dotIndex = javaVersion.indexOf('.'); ++ private static int getJvmVersion() { ++ String javaVersion = System.getProperty("java.version"); ++ int dotIndex = javaVersion.indexOf('.'); + + if (javaVersion.startsWith("1.")) { -+ // definitely old -+ PaperJvmChecker.printWarning(javaVersion, logger); -+ return; ++ // 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); + -+ final int javaVersionNum; + try { -+ javaVersionNum = Integer.parseInt(version); ++ return Integer.parseInt(version); + } catch (final NumberFormatException e) { -+ logger.warn("Failed to determine Java version; Could not parse {}", version, e); -+ PaperJvmChecker.printWarning(javaVersion, logger); -+ return; -+ } -+ -+ if (javaVersionNum < 11) { -+ PaperJvmChecker.printWarning(javaVersion, logger); ++ LogManager.getLogger().warn("Failed to determine Java version; Could not parse {}", version, e); ++ return -1; + } + } + -+ private static void printWarning(final String version, final Logger logger) { -+ 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: " + version); -+ logger.warn("*"); -+ logger.warn("* Check this forum post for more information: "); -+ logger.warn("* https://papermc.io/java11"); -+ logger.warn("************************************************************"); ++ 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