Clean plugin folder logic in extra-jars patch (Fixes #6347) (#6619)

This commit is contained in:
Shane Freeder 2021-10-15 22:54:22 +01:00
parent 26639f1397
commit 38d5d85fe4
2 changed files with 75 additions and 16 deletions

View File

@ -6,18 +6,58 @@ Subject: [PATCH] Add command line option to load extra plugin jars not in the
ex: java -jar paperclip.jar nogui -add-plugin=/path/to/plugin.jar -add-plugin=/path/to/another/plugin_jar.jar 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -0,0 +0,0 @@ public final class Bukkit {
return server.getCurrentTick();
}
+ /**
+ * 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();
+ }
+
/**
* Checks if the server is in the process of being shutdown.
*
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
int getCurrentTick();
+ /**
+ * 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();
+
/**
* Checks if the server is in the process of being shutdown.
*
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -0,0 +0,0 @@ public final class SimplePluginManager implements PluginManager {
private final Map<String, Map<Permissible, Boolean>> permSubs = new HashMap<String, Map<Permissible, Boolean>>();
private final Map<Boolean, Map<Permissible, Boolean>> defSubs = new HashMap<Boolean, Map<Permissible, Boolean>>();
private boolean useTimings = false;
+ private File pluginsDirectory; public @Nullable File pluginsDirectory() { return this.pluginsDirectory; } // Paper
public SimplePluginManager(@NotNull Server instance, @NotNull SimpleCommandMap commandMap) {
server = instance;
@@ -0,0 +0,0 @@ public final class SimplePluginManager implements PluginManager { @@ -0,0 +0,0 @@ public final class SimplePluginManager implements PluginManager {
@Override @Override
@NotNull @NotNull
@ -27,7 +67,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ @NotNull + @NotNull
+ public Plugin[] loadPlugins(final @NotNull File directory, final @NotNull List<File> extraPluginJars) { + public Plugin[] loadPlugins(final @NotNull File directory, final @NotNull List<File> extraPluginJars) {
+ this.pluginsDirectory = directory;
+ // Paper end + // Paper end
Validate.notNull(directory, "Directory cannot be null"); Validate.notNull(directory, "Directory cannot be null");
Validate.isTrue(directory.isDirectory(), "Directory must be a directory"); Validate.isTrue(directory.isDirectory(), "Directory must be a directory");
@ -136,7 +175,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} }
- final File parentFile = file.getParentFile(); - final File parentFile = file.getParentFile();
+ final File parentFile = ((SimplePluginManager) this.server.getPluginManager()).pluginsDirectory(); // Paper + final File parentFile = this.server.getPluginsFolder(); // Paper
final File dataFolder = new File(parentFile, description.getName()); final File dataFolder = new File(parentFile, description.getName());
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
final File oldDataFolder = new File(parentFile, description.getRawName()); final File oldDataFolder = new File(parentFile, description.getRawName());

View File

@ -11,8 +11,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -0,0 +0,0 @@ public final class CraftServer implements Server { @@ -0,0 +0,0 @@ public final class CraftServer implements Server {
public void loadPlugins() {
this.pluginManager.registerInterface(JavaPluginLoader.class);
File pluginFolder = (File) console.options.valueOf("plugins"); - File pluginFolder = (File) console.options.valueOf("plugins");
+ File pluginFolder = this.getPluginsFolder(); // Paper
- if (pluginFolder.exists()) { - if (pluginFolder.exists()) {
- Plugin[] plugins = this.pluginManager.loadPlugins(pluginFolder); - Plugin[] plugins = this.pluginManager.loadPlugins(pluginFolder);
@ -31,14 +34,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} }
+ // Paper start + // Paper start
+ @Override
+ public File getPluginsFolder() {
+ return (File) this.console.options.valueOf("plugins");
+ }
+
+ private List<File> extraPluginJars() { + private List<File> extraPluginJars() {
+ @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked")
+ final List<File> jars = (List<File>) this.console.options.valuesOf("add-plugin"); + final List<File> jars = (List<File>) this.console.options.valuesOf("add-plugin");
+ return jars.stream() + final List<File> list = new ArrayList<>();
+ .filter(File::exists) + for (final File file : jars) {
+ .filter(File::isFile) + if (!file.exists()) {
+ .filter(file -> file.getName().endsWith(".jar")) + MinecraftServer.LOGGER.warn("File '{}' specified through 'add-plugin' argument does not exist, cannot load a plugin from it!", file.getAbsolutePath());
+ .collect(java.util.stream.Collectors.toList()); + continue;
+ }
+ if (!file.isFile()) {
+ MinecraftServer.LOGGER.warn("File '{}' specified through 'add-plugin' argument is not a file, cannot load a plugin from it!", file.getAbsolutePath());
+ continue;
+ }
+ if (!file.getName().endsWith(".jar")) {
+ MinecraftServer.LOGGER.warn("File '{}' specified through 'add-plugin' argument is not a jar file, cannot load a plugin from it!", file.getAbsolutePath());
+ continue;
+ }
+ list.add(file);
+ }
+ return list;
+ } + }
+ // Paper end + // Paper end
+ +