2022-04-18 18:12:39 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Xemorr <31805746+Xemorr@users.noreply.github.com>
|
|
|
|
Date: Fri, 1 Apr 2022 19:57:40 +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
|
2022-07-23 06:52:57 +02:00
|
|
|
index 94646b37c77fcb18fc4030306c431684e7e9a5cc..9db611841b73fed8dc8a71f4d7fdef95af3cf89d 100644
|
2022-04-18 18:12:39 +02:00
|
|
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
|
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
2022-07-21 21:53:04 +02:00
|
|
|
@@ -396,7 +396,7 @@ public final class SimplePluginManager implements PluginManager {
|
2022-04-18 18:12:39 +02:00
|
|
|
public synchronized Plugin loadPlugin(@NotNull File file) throws InvalidPluginException, UnknownDependencyException {
|
2022-06-07 19:20:30 +02:00
|
|
|
Preconditions.checkArgument(file != null, "File cannot be null");
|
2022-04-18 18:12:39 +02:00
|
|
|
|
|
|
|
- checkUpdate(file);
|
|
|
|
+ file = checkUpdate(file); // Paper - update the reference in case checkUpdate renamed it
|
|
|
|
|
|
|
|
Set<Pattern> filters = fileAssociations.keySet();
|
|
|
|
Plugin result = null;
|
2022-07-21 21:53:04 +02:00
|
|
|
@@ -423,16 +423,61 @@ public final class SimplePluginManager implements PluginManager {
|
2022-04-18 18:12:39 +02:00
|
|
|
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;
|
Ignore invalid jars inside of the updates folder (Fixes #7751)
This really needs a deeper look here, the way updates are handled is
fairly immature, but, this wasn't ever intended to be a large scale thing
Ideally, imho, we'd collect the list of update files into some form of Map,
that way we just have a reference of Name > File refs, and can filter out
cases where there are two versions of a plugin in there and warn expectidely,
but, that creates some complications, you would need to fall back to a dir
scan in the case of a plugin calling loadPlugin, but, it would at least
give us more defined behavior, as well as improve performance here vs
repeatidely trying to deserialise the plugin.yml defs for every file
in there on every load
2022-04-20 11:00:50 +02:00
|
|
|
+ }
|
2022-04-18 18:12:39 +02:00
|
|
|
+ PluginLoader pluginLoader = getPluginLoader(file);
|
|
|
|
+ try {
|
|
|
|
+ String pluginName = pluginLoader.getPluginDescription(file).getName();
|
|
|
|
+ for (File updateFile : updateDirectory.listFiles()) {
|
|
|
|
+ if (!updateFile.isFile()) continue;
|
|
|
|
+ PluginLoader updatePluginLoader = getPluginLoader(updateFile);
|
|
|
|
+ if (updatePluginLoader == null) continue;
|
Ignore invalid jars inside of the updates folder (Fixes #7751)
This really needs a deeper look here, the way updates are handled is
fairly immature, but, this wasn't ever intended to be a large scale thing
Ideally, imho, we'd collect the list of update files into some form of Map,
that way we just have a reference of Name > File refs, and can filter out
cases where there are two versions of a plugin in there and warn expectidely,
but, that creates some complications, you would need to fall back to a dir
scan in the case of a plugin calling loadPlugin, but, it would at least
give us more defined behavior, as well as improve performance here vs
repeatidely trying to deserialise the plugin.yml defs for every file
in there on every load
2022-04-20 11:00:50 +02:00
|
|
|
+ String updatePluginName;
|
|
|
|
+ try {
|
|
|
|
+ updatePluginName = updatePluginLoader.getPluginDescription(updateFile).getName();
|
|
|
|
+ // We failed to load this data for some reason, so, we'll skip over this
|
|
|
|
+ } catch (InvalidDescriptionException ex) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
2022-04-18 18:12:39 +02:00
|
|
|
+ if (!pluginName.equals(updatePluginName)) continue;
|
2022-07-18 11:31:33 +02:00
|
|
|
+ try {
|
2022-07-23 06:52:57 +02:00
|
|
|
+ java.nio.file.Files.copy(updateFile.toPath(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
2022-07-18 11:31:33 +02:00
|
|
|
+ } catch (java.io.IOException exception) {
|
|
|
|
+ server.getLogger().log(Level.SEVERE, "Could not copy '" + updateFile.getPath() + "' to '" + file.getPath() + "' in update plugin process", exception);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
2022-04-18 18:12:39 +02:00
|
|
|
+ File newName = new File(file.getParentFile(), updateFile.getName());
|
|
|
|
+ file.renameTo(newName);
|
|
|
|
+ updateFile.delete();
|
|
|
|
+ return newName;
|
|
|
|
+ }
|
2022-07-18 11:31:33 +02:00
|
|
|
}
|
2022-04-18 18:12:39 +02:00
|
|
|
+ catch (InvalidDescriptionException e) {
|
|
|
|
+ throw new InvalidPluginException(e);
|
2022-07-18 11:31:33 +02:00
|
|
|
+ }
|
2022-04-18 18:12:39 +02:00
|
|
|
+ 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
|