plugin manager updates

This commit is contained in:
Jason Penilla 2024-04-25 23:17:15 -07:00
parent c9e0e1f9f3
commit 898fa27a8f

View file

@ -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<MultiRuntimePluginProviderStorage> runtimePluginEntrypointHandler = new RuntimePluginEntrypointHandler<>(new MultiRuntimePluginProviderStorage(this.dependencyTree));
+ try {
+ List<Path> 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<File[], List<Path>> {
+
+ 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<Path> prepareContext(File[] context) {
+ final List<Path> 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<Path> 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