From 898fa27a8f2801411b3e6853b69d6a1ebbc5aa32 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Thu, 25 Apr 2024 23:17:15 -0700 Subject: [PATCH] plugin manager updates --- patches/server/Paper-Plugins.patch | 73 +++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/patches/server/Paper-Plugins.patch b/patches/server/Paper-Plugins.patch index be083a9f31..1a3efcae08 100644 --- a/patches/server/Paper-Plugins.patch +++ b/patches/server/Paper-Plugins.patch @@ -3787,7 +3787,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import io.papermc.paper.plugin.provider.classloader.ConfiguredPluginClassLoader; +import io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage; +import io.papermc.paper.plugin.provider.source.DirectoryProviderSource; ++import io.papermc.paper.plugin.provider.source.FileArrayProviderSource; +import io.papermc.paper.plugin.provider.source.FileProviderSource; ++import java.io.File; +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.World; @@ -3798,7 +3800,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.bukkit.event.HandlerList; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; -+import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; @@ -3808,7 +3809,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -+import org.spongepowered.configurate.serialize.SerializationException; + +import java.io.IOException; +import java.nio.file.Files; @@ -3898,6 +3898,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + .orElseThrow(() -> new InvalidPluginException("Plugin didn't load any plugin providers?")); + } + ++ public @NotNull Plugin[] loadPlugins(@NotNull File[] files) { ++ RuntimePluginEntrypointHandler runtimePluginEntrypointHandler = new RuntimePluginEntrypointHandler<>(new MultiRuntimePluginProviderStorage(this.dependencyTree)); ++ try { ++ List paths = FileArrayProviderSource.INSTANCE.prepareContext(files); ++ DirectoryProviderSource.INSTANCE.registerProviders(runtimePluginEntrypointHandler, paths); ++ runtimePluginEntrypointHandler.enter(Entrypoint.PLUGIN); ++ } catch (Exception e) { ++ // This should never happen, any errors that occur in this provider should instead be logged. ++ this.server.getLogger().log(Level.SEVERE, "Unknown error occurred while loading plugins through PluginManager.", e); ++ } ++ ++ return runtimePluginEntrypointHandler.getPluginProviderStorage().getLoaded().toArray(new JavaPlugin[0]); ++ } ++ + // The behavior of this is that all errors are logged instead of being thrown + public @NotNull Plugin[] loadPlugins(@NotNull Path directory) { + Preconditions.checkArgument(Files.isDirectory(directory), "Directory must be a directory"); // Avoid creating a directory if it doesn't exist @@ -4173,6 +4187,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + @Override ++ public @NotNull Plugin[] loadPlugins(final @NotNull File[] files) { ++ return this.instanceManager.loadPlugins(files); ++ } ++ ++ @Override + public void disablePlugins() { + this.instanceManager.disablePlugins(); + } @@ -5550,6 +5569,56 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return Files.isRegularFile(path) && !path.startsWith("."); + } +} +diff --git a/src/main/java/io/papermc/paper/plugin/provider/source/FileArrayProviderSource.java b/src/main/java/io/papermc/paper/plugin/provider/source/FileArrayProviderSource.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/plugin/provider/source/FileArrayProviderSource.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.plugin.provider.source; ++ ++import com.mojang.logging.LogUtils; ++import io.papermc.paper.plugin.entrypoint.EntrypointHandler; ++import java.io.File; ++import java.nio.file.Path; ++import java.util.ArrayList; ++import java.util.List; ++import org.slf4j.Logger; ++ ++public class FileArrayProviderSource implements ProviderSource> { ++ ++ public static final FileArrayProviderSource INSTANCE = new FileArrayProviderSource(); ++ private static final FileProviderSource FILE_PROVIDER_SOURCE = new FileProviderSource("File '%s'"::formatted); ++ private static final Logger LOGGER = LogUtils.getClassLogger(); ++ ++ @Override ++ public List prepareContext(File[] context) { ++ final List files = new ArrayList<>(); ++ for (File file : context) { ++ try { ++ files.add(FILE_PROVIDER_SOURCE.prepareContext(file.toPath())); ++ } catch (IllegalArgumentException ignored) { ++ // Ignore illegal argument exceptions from jar checking ++ } catch (final Exception e) { ++ LOGGER.error("Error preparing plugin context: " + e.getMessage(), e); ++ } ++ } ++ return files; ++ } ++ ++ @Override ++ public void registerProviders(EntrypointHandler entrypointHandler, List context) { ++ for (Path path : context) { ++ try { ++ FILE_PROVIDER_SOURCE.registerProviders(entrypointHandler, path); ++ } catch (IllegalArgumentException ignored) { ++ // Ignore illegal argument exceptions from jar checking ++ } catch (Exception e) { ++ LOGGER.error("Error loading plugin: " + e.getMessage(), e); ++ } ++ } ++ } ++} 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..0000000000000000000000000000000000000000