Small paper plugin fixes (#8866)
Co-authored-by: Bjarne Koll <lynxplay101@gmail.com> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
parent
8c4e81184b
commit
0e4f2cc527
5 changed files with 194 additions and 161 deletions
|
@ -1218,72 +1218,6 @@ index 0000000000000000000000000000000000000000..44d630c3eb2670c36134b9907519dc98
|
|||
+ boolean hasDependency(@NotNull String pluginIdentifier);
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/util/DummyBukkitPluginLoader.java b/src/main/java/io/papermc/paper/plugin/provider/util/DummyBukkitPluginLoader.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..c912ee020937f1ce16481c108e332e45acba5ff9
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/provider/util/DummyBukkitPluginLoader.java
|
||||
@@ -0,0 +1,60 @@
|
||||
+package io.papermc.paper.plugin.provider.util;
|
||||
+
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.event.Event;
|
||||
+import org.bukkit.event.Listener;
|
||||
+import org.bukkit.plugin.InvalidDescriptionException;
|
||||
+import org.bukkit.plugin.InvalidPluginException;
|
||||
+import org.bukkit.plugin.Plugin;
|
||||
+import org.bukkit.plugin.PluginDescriptionFile;
|
||||
+import org.bukkit.plugin.PluginLoader;
|
||||
+import org.bukkit.plugin.RegisteredListener;
|
||||
+import org.bukkit.plugin.UnknownDependencyException;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.io.File;
|
||||
+import java.util.Map;
|
||||
+import java.util.Set;
|
||||
+import java.util.regex.Pattern;
|
||||
+
|
||||
+/**
|
||||
+ * A purely internal type that implements the now deprecated {@link PluginLoader} after the implementation
|
||||
+ * of papers new plugin system.
|
||||
+ *
|
||||
+ * @param plugin the loaded plugin that should be wrapped by this NOOP implementation
|
||||
+ */
|
||||
+@ApiStatus.Internal
|
||||
+public record DummyBukkitPluginLoader(Plugin plugin) implements PluginLoader {
|
||||
+
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull Plugin loadPlugin(@NotNull File file) throws InvalidPluginException, UnknownDependencyException {
|
||||
+ throw new UnsupportedOperationException();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull PluginDescriptionFile getPluginDescription(@NotNull File file) throws InvalidDescriptionException {
|
||||
+ throw new UnsupportedOperationException();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull Pattern[] getPluginFileFilters() {
|
||||
+ throw new UnsupportedOperationException();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull Map<Class<? extends Event>, Set<RegisteredListener>> createRegisteredListeners(@NotNull Listener listener, @NotNull Plugin plugin) {
|
||||
+ throw new UnsupportedOperationException();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void enablePlugin(@NotNull Plugin plugin) {
|
||||
+ Bukkit.getPluginManager().enablePlugin(plugin);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void disablePlugin(@NotNull Plugin plugin) {
|
||||
+ Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/util/ProviderUtil.java b/src/main/java/io/papermc/paper/plugin/provider/util/ProviderUtil.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..6bf3d212a6156ad9ab0e82d1ca0a04f83f6e4b83
|
||||
|
@ -1901,7 +1835,7 @@ index a80251eff75430863b37db1c131e22593f3fcd5e..310c4041963a3f1e0a26e39a6da12a9b
|
|||
+ // Paper end
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
|
||||
index 669a70faa95d0d6525a731d73499ed6fb0b48320..a5636b1f223dd37420a4acbccf28f7198a7eee98 100644
|
||||
index 669a70faa95d0d6525a731d73499ed6fb0b48320..6175b04327b12e74140a0885f7326546dfaf269a 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
|
||||
@@ -38,6 +38,7 @@ public abstract class JavaPlugin extends PluginBase {
|
||||
|
@ -1977,7 +1911,7 @@ index 669a70faa95d0d6525a731d73499ed6fb0b48320..a5636b1f223dd37420a4acbccf28f719
|
|||
if (isEnabled != enabled) {
|
||||
isEnabled = enabled;
|
||||
|
||||
@@ -268,9 +283,14 @@ public abstract class JavaPlugin extends PluginBase {
|
||||
@@ -268,9 +283,18 @@ public abstract class JavaPlugin extends PluginBase {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1985,17 +1919,21 @@ index 669a70faa95d0d6525a731d73499ed6fb0b48320..a5636b1f223dd37420a4acbccf28f719
|
|||
- final void init(@NotNull PluginLoader loader, @NotNull Server server, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file, @NotNull ClassLoader classLoader) {
|
||||
- this.loader = loader;
|
||||
+ // Paper start
|
||||
+ private static class DummyPluginLoaderImplHolder {
|
||||
+ private static final PluginLoader INSTANCE = net.kyori.adventure.util.Services.service(PluginLoader.class)
|
||||
+ .orElseThrow();
|
||||
+ }
|
||||
+ public final void init(@NotNull PluginLoader loader, @NotNull Server server, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file, @NotNull ClassLoader classLoader) {
|
||||
+ init(server, description, dataFolder, file, classLoader, description);
|
||||
+ this.pluginMeta = description;
|
||||
+ }
|
||||
+ public final void init(@NotNull Server server, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file, @NotNull ClassLoader classLoader, @Nullable io.papermc.paper.plugin.configuration.PluginMeta configuration) {
|
||||
+ // Paper end
|
||||
+ this.loader = new io.papermc.paper.plugin.provider.util.DummyBukkitPluginLoader(this);
|
||||
+ this.loader = DummyPluginLoaderImplHolder.INSTANCE; // Paper
|
||||
this.server = server;
|
||||
this.file = file;
|
||||
this.description = description;
|
||||
@@ -278,6 +298,7 @@ public abstract class JavaPlugin extends PluginBase {
|
||||
@@ -278,6 +302,7 @@ public abstract class JavaPlugin extends PluginBase {
|
||||
this.classLoader = classLoader;
|
||||
this.configFile = new File(dataFolder, "config.yml");
|
||||
this.logger = new PluginLogger(this);
|
||||
|
@ -2049,7 +1987,7 @@ index 6d634b0ea813ccb19f1562a7d0e5a59cea4eab21..f9e67e20133d349e43d126dbb48b34d4
|
|||
|
||||
private final Logger logger;
|
||||
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
index 2f74ec96ece706de23156ebabfe493211bc05391..e721c58eafee2180d4ba1a73002cf850355a366e 100644
|
||||
index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61f96ab4b3 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
||||
@@ -29,7 +29,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
@ -2134,7 +2072,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..e721c58eafee2180d4ba1a73002cf850
|
|||
|
||||
if (result != null) {
|
||||
// If the class was loaded from a library instead of a PluginClassLoader, we can assume that its associated plugin is a transitive dependency and can therefore skip this check.
|
||||
@@ -128,7 +153,7 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
@@ -128,14 +153,14 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
|
||||
if (provider != description
|
||||
&& !seenIllegalAccess.contains(provider.getName())
|
||||
|
@ -2143,6 +2081,14 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..e721c58eafee2180d4ba1a73002cf850
|
|||
|
||||
seenIllegalAccess.add(provider.getName());
|
||||
if (plugin != null) {
|
||||
plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend or softdepend of this plugin.", new Object[]{name, provider.getFullName()});
|
||||
} else {
|
||||
// In case the bad access occurs on construction
|
||||
- loader.server.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend or softdepend of this plugin.", new Object[]{description.getName(), name, provider.getFullName()});
|
||||
+ org.bukkit.Bukkit.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend or softdepend of this plugin.", new Object[]{description.getName(), name, provider.getFullName()}); // Paper
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +192,7 @@ final class PluginClassLoader extends URLClassLoader {
|
||||
throw new ClassNotFoundException(name, ex);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue