aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRiley Park <[email protected]>2024-07-20 13:00:29 -0700
committerRiley Park <[email protected]>2024-07-20 13:00:29 -0700
commit9aea24002a7b94f944d7275e7d9b0235772583b4 (patch)
treeda193cb46bf50aa6d36f4e12eb571a8a383df7d2
parentaa3b3568346838aa175add0b005efc020de0ba81 (diff)
downloadPaper-9aea24002a7b94f944d7275e7d9b0235772583b4.tar.gz
Paper-9aea24002a7b94f944d7275e7d9b0235772583b4.zip
Properly lookup plugin classes when looked up by spark
fixes #11124
-rw-r--r--patches/server/1043-Bundle-spark.patch84
1 files changed, 81 insertions, 3 deletions
diff --git a/patches/server/1043-Bundle-spark.patch b/patches/server/1043-Bundle-spark.patch
index a44d3aa1b2..5dabc8982f 100644
--- a/patches/server/1043-Bundle-spark.patch
+++ b/patches/server/1043-Bundle-spark.patch
@@ -21,13 +21,15 @@ index 1a734293c9416f13324bb0edf8f950c9029f8bc4..568d0b65bb5010e0ab365cb47b624720
paperweight {
diff --git a/src/main/java/io/papermc/paper/SparksFly.java b/src/main/java/io/papermc/paper/SparksFly.java
new file mode 100644
-index 0000000000000000000000000000000000000000..785e85465c746dd66d1d3d648746cb1487d16d07
+index 0000000000000000000000000000000000000000..d589ae2aa89f386d96e4ff51dbc9f2aae1703598
--- /dev/null
+++ b/src/main/java/io/papermc/paper/SparksFly.java
-@@ -0,0 +1,179 @@
+@@ -0,0 +1,200 @@
+package io.papermc.paper;
+
+import io.papermc.paper.configuration.GlobalConfiguration;
++import io.papermc.paper.plugin.ClassLoaderStorage;
++import io.papermc.paper.plugin.entrypoint.classloader.PaperSimplePluginClassLoader;
+import io.papermc.paper.util.MCUtil;
+import java.util.List;
+import java.util.logging.Level;
@@ -42,6 +44,7 @@ index 0000000000000000000000000000000000000000..785e85465c746dd66d1d3d648746cb14
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.CraftServer;
++import org.bukkit.plugin.java.PluginClassLoader;
+
+// It's like electricity.
+public final class SparksFly {
@@ -84,7 +87,25 @@ index 0000000000000000000000000000000000000000..785e85465c746dd66d1d3d648746cb14
+ }, new PaperClassLookup() {
+ @Override
+ public Class<?> lookup(final String className) throws Exception {
-+ return Class.forName(className);
++ try {
++ return Class.forName(className);
++ } catch (final Exception e) {
++ for (final PaperSimplePluginClassLoader loader : ClassLoaderStorage.MODERN_LOADERS) {
++ final Class<?> loadedClass = loader.loadClass(className);
++ if (loadedClass != null) {
++ return loadedClass;
++ }
++ }
++ for (final PluginClassLoader loader : ClassLoaderStorage.LEGACY_LOADERS) {
++ final Class<?> loadedClass = loader.loadClass(className, true, false, true);
++ if (loadedClass != null) {
++ return loadedClass;
++ }
++ }
++ final ClassNotFoundException exception = new ClassNotFoundException("Could not find class " + className);
++ exception.addSuppressed(e);
++ throw exception;
++ }
+ }
+ });
+ }
@@ -204,6 +225,43 @@ index 0000000000000000000000000000000000000000..785e85465c746dd66d1d3d648746cb14
+ }
+ }
+}
+diff --git a/src/main/java/io/papermc/paper/plugin/ClassLoaderStorage.java b/src/main/java/io/papermc/paper/plugin/ClassLoaderStorage.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..cb080d89b3be899de5007c799e6ef40809f2ef61
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/plugin/ClassLoaderStorage.java
+@@ -0,0 +1,11 @@
++package io.papermc.paper.plugin;
++
++import io.papermc.paper.plugin.entrypoint.classloader.PaperSimplePluginClassLoader;
++import java.util.HashSet;
++import java.util.Set;
++import org.bukkit.plugin.java.PluginClassLoader;
++
++public final class ClassLoaderStorage {
++ public static final Set<PaperSimplePluginClassLoader> MODERN_LOADERS = new HashSet<>();
++ public static final Set<PluginClassLoader> LEGACY_LOADERS = new HashSet<>();
++}
+diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java
+index 967465e542483e93a736129b5f5c6622cefd33fa..f8094525064b46fe78f5b5f32ea53b234b4d525d 100644
+--- a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java
++++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperSimplePluginClassLoader.java
+@@ -1,5 +1,6 @@
+ package io.papermc.paper.plugin.entrypoint.classloader;
+
++import io.papermc.paper.plugin.ClassLoaderStorage;
+ import io.papermc.paper.plugin.configuration.PluginMeta;
+ import io.papermc.paper.plugin.util.NamespaceChecker;
+ import org.jetbrains.annotations.ApiStatus;
+@@ -40,6 +41,8 @@ public class PaperSimplePluginClassLoader extends URLClassLoader {
+ this.jarUrl = source.toUri().toURL();
+ this.configuration = configuration;
+ this.jar = file;
++
++ ClassLoaderStorage.MODERN_LOADERS.add(this); // Paper - spark
+ }
+
+ @Override
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
index 6b8ed8a0baaf4a57d20e57cec3400af5561ddd79..48604e7f96adc9e226e034054c5e2bad0b024eb5 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/source/FileProviderSource.java
@@ -246,6 +304,26 @@ index 6b8ed8a0baaf4a57d20e57cec3400af5561ddd79..48604e7f96adc9e226e034054c5e2bad
type.register(entrypointHandler, file, context);
}
+diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java
+index 0fd1040ed376f19c6d5326767baaf3048ce1bfb4..a9fd3f34aca19b1cfada5b771b3d46a2cfca4c51 100644
+--- a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java
++++ b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProvider.java
+@@ -2,6 +2,7 @@ package io.papermc.paper.plugin.provider.type.spigot;
+
+ import com.destroystokyo.paper.util.SneakyThrow;
+ import com.destroystokyo.paper.utils.PaperPluginLogger;
++import io.papermc.paper.plugin.ClassLoaderStorage;
+ import io.papermc.paper.plugin.manager.PaperPluginManagerImpl;
+ import io.papermc.paper.plugin.provider.configuration.LoadOrderConfiguration;
+ import io.papermc.paper.plugin.provider.entrypoint.DependencyContext;
+@@ -133,6 +134,7 @@ public class SpigotPluginProvider implements PluginProvider<JavaPlugin>, Provide
+ // We must provide a temporary context in order to properly handle dependencies on the plugin classloader constructor.
+ loader.dependencyContext = PaperPluginManagerImpl.getInstance();
+
++ ClassLoaderStorage.LEGACY_LOADERS.add(loader); // Paper - spark
+
+ this.status = ProviderStatus.INITIALIZED;
+ return loader.getPlugin();
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 8160c35368fc2c52d6f4a42df27adb2ef6eb87f3..9325d6f95165a7cee00d7de736af723681cc16b4 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java