diff --git a/patches/api/0332-Update-Folder-Uses-Plugin-Name.patch b/patches/api/0332-Update-Folder-Uses-Plugin-Name.patch new file mode 100644 index 000000000000..395a20f6cd67 --- /dev/null +++ b/patches/api/0332-Update-Folder-Uses-Plugin-Name.patch @@ -0,0 +1,78 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: samue +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 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); ++ 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 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