From 69b52b4d8edc242cffd61c68dadf7208b508ce4e Mon Sep 17 00:00:00 2001 From: Micah Rao <49841276+jstN0body@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:05:13 -0500 Subject: [PATCH] Check for server JARs in plugin directory (#10228) --- patches/server/0013-Paper-Plugins.patch | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/patches/server/0013-Paper-Plugins.patch b/patches/server/0013-Paper-Plugins.patch index 9d5b2ad42e..db0f1755aa 100644 --- a/patches/server/0013-Paper-Plugins.patch +++ b/patches/server/0013-Paper-Plugins.patch @@ -3,6 +3,7 @@ From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Wed, 6 Jul 2022 23:00:31 -0400 Subject: [PATCH] Paper Plugins +Co-authored-by: Micah Rao diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java index 8ccc59473bac983ced6b9e4a57e0ec4ebd2b0f32..6d06b772ffb9d47d6a717462a4b2b494544e80ae 100644 @@ -5551,10 +5552,10 @@ index 0000000000000000000000000000000000000000..f30fcf60b64150e381c7b813016aa9dd +} diff --git a/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java b/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java new file mode 100644 -index 0000000000000000000000000000000000000000..d33762ce5977636320e324dde4aab37075865d8d +index 0000000000000000000000000000000000000000..5b58df8df7efca0f67e3a14dd71051dfd7a26079 --- /dev/null +++ b/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java -@@ -0,0 +1,163 @@ +@@ -0,0 +1,171 @@ +package io.papermc.paper.plugin.provider.source; + +import io.papermc.paper.plugin.PluginInitializerManager; @@ -5617,7 +5618,15 @@ index 0000000000000000000000000000000000000000..d33762ce5977636320e324dde4aab370 + JarFile file = new JarFile(context.toFile(), true, JarFile.OPEN_READ, JarFile.runtimeVersion()); + PluginFileType type = PluginFileType.guessType(file); + if (type == null) { -+ throw new IllegalArgumentException(source + " does not contain a " + String.join(" or ", PluginFileType.getConfigTypes()) + "! Could not determine plugin type, cannot load a plugin from it!"); ++ // Throw IAE wrapped in RE to prevent callers from considering this a "invalid parameter" as caller ignores IAE. ++ // TODO: This needs some heavy rework, using illegal argument exception to signal an actual failure is less than ideal. ++ if (file.getEntry("META-INF/versions.list") != null) { ++ throw new RuntimeException(new IllegalArgumentException(context + " appears to be a server jar! Server jars do not belong in the plugin folder.")); ++ } ++ ++ throw new RuntimeException( ++ new IllegalArgumentException(source + " does not contain a " + String.join(" or ", PluginFileType.getConfigTypes()) + "! Could not determine plugin type, cannot load a plugin from it!") ++ ); + } + + type.register(entrypointHandler, file, context);