Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions patches/api/0332-Update-Folder-Uses-Plugin-Name.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: samue <xemoryt@gmail.com>
Date: Tue, 7 Sep 2021 18:11:37 +0100
Subject: [PATCH] Update-Folder-Uses-Plugin-Name


diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index 0e25119564dfa9cb12f3c5dc5f653d7f2c147a9d..e8b3e3bdebb447a12f67642cd914d52cbee10c65 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -399,7 +399,7 @@ public final class SimplePluginManager implements PluginManager {
public synchronized Plugin loadPlugin(@NotNull File file) throws InvalidPluginException, UnknownDependencyException {
Validate.notNull(file, "File cannot be null");

- checkUpdate(file);
+ file = checkUpdate(file); // Paper - update the reference in case checkUpdate renamed it

Set<Pattern> filters = fileAssociations.keySet();
Plugin result = null;
@@ -426,16 +426,53 @@ public final class SimplePluginManager implements PluginManager {
return result;
}

- private void checkUpdate(@NotNull File file) {
+ // Paper start - Update Folder Uses Plugin Name to replace
+ /**
+ * Replaces a plugin with a plugin of the same plugin name in the update folder.
+ * @param file
+ * @throws InvalidPluginException
+ */
+ private File checkUpdate(@NotNull File file) throws InvalidPluginException {
if (updateDirectory == null || !updateDirectory.isDirectory()) {
- return;
+ return file;
+ }
+ PluginLoader pluginLoader = getPluginLoader(file);
+ try {
+ String pluginName = pluginLoader.getPluginDescription(file).getName();
+ for (File updateFile : updateDirectory.listFiles()) {
+ if (updateFile.isFile()) {
+ PluginLoader updatePluginLoader = getPluginLoader(updateFile);
Comment thread
Xemorr marked this conversation as resolved.
+ if (updatePluginLoader == null) continue;
+ String updatePluginName = updatePluginLoader.getPluginDescription(updateFile).getName();
+ if (pluginName.equals(updatePluginName)) {
+ if (FileUtil.copy(updateFile, file)) {
+ File newName = new File(file.getParentFile(), updateFile.getName());
+ file.renameTo(newName);
+ updateFile.delete();
+ return newName;
+ }
+ }
+ }
+ }
}
+ catch (InvalidDescriptionException e) {
+ throw new InvalidPluginException(e);
+ }
+ return file;
+ }

- File updateFile = new File(updateDirectory, file.getName());
- if (updateFile.isFile() && FileUtil.copy(updateFile, file)) {
- updateFile.delete();
+ @Nullable
+ private PluginLoader getPluginLoader(File file) {
+ Set<Pattern> filters = fileAssociations.keySet();
+ for (Pattern filter : filters) {
+ Matcher match = filter.matcher(file.getName());
+ if (match.find()) {
+ return fileAssociations.get(filter);
+ }
}
+ return null;
}
+ // Paper end

/**
* Checks if the given plugin is loaded and returns it when applicable