-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Improved Update Folder behaviour #6575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
824110c
Improved Update Folder behaviour, it now replaces based on the plugin…
c459b37
Added Paper comments
6daabaf
Ignore null plugin loaders as this means the file extension isn't valid
665fb2a
Added spaces to beginning of paper comments
2dc20f4
readded new line to minimise diff
2eb39b2
Merge branch 'PaperMC:master' into master
Xemorr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| + 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.