Paper/patches/api/0011-Add-command-line-option-to-load-extra-plugin-jars-no.patch
2023-02-19 08:57:10 -06:00

97 lines
4.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Tue, 18 May 2021 14:42:26 -0700
Subject: [PATCH] Add command line option to load extra plugin jars not in the
plugins folder
ex: java -jar paperclip.jar nogui -add-plugin=/path/to/plugin.jar -add-plugin=/path/to/another/plugin_jar.jar
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index e24589a4cb42b0163e4a1455b8b11d7130b5cd41..71a09ed2b9863d2d339967f41ab6373ec27429d3 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -76,6 +76,20 @@ public final class Bukkit {
return server;
}
+ /**
+ * Returns the de facto plugins directory, generally used for storing plugin jars to be loaded,
+ * as well as their {@link org.bukkit.plugin.Plugin#getDataFolder() data folders}.
+ *
+ * <p>Plugins should use {@link org.bukkit.plugin.Plugin#getDataFolder()} rather than traversing this
+ * directory manually when determining the location in which to store their data and configuration files.</p>
+ *
+ * @return plugins directory
+ */
+ @NotNull
+ public static File getPluginsFolder() {
+ return server.getPluginsFolder();
+ }
+
/**
* Attempts to set the {@link Server} singleton.
* <p>
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index ac087402c90dad4b3c499fcf8507e50e9099cea5..a4f8035b40eebff8afe01788781128b04247f28c 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -61,6 +61,18 @@ import org.jetbrains.annotations.Nullable;
*/
public interface Server extends PluginMessageRecipient, net.kyori.adventure.audience.ForwardingAudience { // Paper
+ /**
+ * Returns the de facto plugins directory, generally used for storing plugin jars to be loaded,
+ * as well as their {@link org.bukkit.plugin.Plugin#getDataFolder() data folders}.
+ *
+ * <p>Plugins should use {@link org.bukkit.plugin.Plugin#getDataFolder()} rather than traversing this
+ * directory manually when determining the location in which to store their data and configuration files.</p>
+ *
+ * @return plugins directory
+ */
+ @NotNull
+ File getPluginsFolder();
+
/**
* Used for all administrative messages, such as an operator using a
* command.
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index f13dcbe448111b24b36105d25527ba87ccc9334e..3fcb73a0fc2daaeb76dd4c6757afce52c5b3118b 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -116,9 +116,22 @@ public final class SimplePluginManager implements PluginManager {
@Override
@NotNull
public Plugin[] loadPlugins(@NotNull File directory) {
+ // Paper start - extra jars
+ return this.loadPlugins(directory, java.util.Collections.emptyList());
+ }
+ @NotNull
+ public Plugin[] loadPlugins(final @NotNull File directory, final @NotNull List<File> extraPluginJars) {
+ // Paper end
if (true) {
List<Plugin> pluginList = new ArrayList<>();
java.util.Collections.addAll(pluginList, this.paperPluginManager.loadPlugins(directory));
+ for (File file : extraPluginJars) {
+ try {
+ pluginList.add(this.paperPluginManager.loadPlugin(file));
+ } catch (Exception e) {
+ this.server.getLogger().log(Level.SEVERE, "Plugin loading error!", e);
+ }
+ }
return pluginList.toArray(new Plugin[0]);
}
Preconditions.checkArgument(directory != null, "Directory cannot be null");
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index 02062284dbc1a6c923ceffa5e4d6a3be8c7429d3..88d852c1a729ffd5951da803da424b31591c9f9a 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -93,7 +93,7 @@ public final class JavaPluginLoader implements PluginLoader {
throw new InvalidPluginException(ex);
}
- final File parentFile = file.getParentFile();
+ final File parentFile = this.server.getPluginsFolder(); // Paper
final File dataFolder = new File(parentFile, description.getName());
@SuppressWarnings("deprecation")
final File oldDataFolder = new File(parentFile, description.getRawName());