mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-09 08:32:07 -07:00
Finish converting most of the undeprecated api to jspecify
This commit is contained in:
@@ -33,20 +33,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.plugin;
|
||||
+
|
||||
+import java.util.List;
|
||||
+import java.util.Set;
|
||||
+import org.bukkit.permissions.Permissible;
|
||||
+import org.bukkit.permissions.Permission;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+import java.util.List;
|
||||
+import java.util.Set;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * A permission manager implementation to keep backwards compatibility partially alive with existing plugins that used
|
||||
+ * the bukkit one before.
|
||||
+ */
|
||||
+@ApiStatus.Experimental
|
||||
+@NullMarked
|
||||
+public interface PermissionManager {
|
||||
+
|
||||
+ /**
|
||||
@@ -55,8 +55,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param name Name of the permission
|
||||
+ * @return Permission, or null if none
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ Permission getPermission(@NotNull String name);
|
||||
+ @Nullable Permission getPermission(String name);
|
||||
+
|
||||
+ /**
|
||||
+ * Adds a {@link Permission} to this plugin manager.
|
||||
@@ -68,7 +67,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @throws IllegalArgumentException Thrown when a permission with the same
|
||||
+ * name already exists
|
||||
+ */
|
||||
+ void addPermission(@NotNull Permission perm);
|
||||
+ void addPermission(Permission perm);
|
||||
+
|
||||
+ /**
|
||||
+ * Removes a {@link Permission} registration from this plugin manager.
|
||||
@@ -81,7 +80,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @param perm Permission to remove
|
||||
+ */
|
||||
+ void removePermission(@NotNull Permission perm);
|
||||
+ void removePermission(Permission perm);
|
||||
+
|
||||
+ /**
|
||||
+ * Removes a {@link Permission} registration from this plugin manager.
|
||||
@@ -94,7 +93,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @param name Permission to remove
|
||||
+ */
|
||||
+ void removePermission(@NotNull String name);
|
||||
+ void removePermission(String name);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the default permissions for the given op status
|
||||
@@ -102,7 +101,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param op Which set of default permissions to get
|
||||
+ * @return The default permissions
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ Set<Permission> getDefaultPermissions(boolean op);
|
||||
+
|
||||
+ /**
|
||||
@@ -113,7 +111,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @param perm Permission to recalculate
|
||||
+ */
|
||||
+ void recalculatePermissionDefaults(@NotNull Permission perm);
|
||||
+ void recalculatePermissionDefaults(Permission perm);
|
||||
+
|
||||
+ /**
|
||||
+ * Subscribes the given Permissible for information about the requested
|
||||
@@ -125,7 +123,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param permission Permission to subscribe to
|
||||
+ * @param permissible Permissible subscribing
|
||||
+ */
|
||||
+ void subscribeToPermission(@NotNull String permission, @NotNull Permissible permissible);
|
||||
+ void subscribeToPermission(String permission, Permissible permissible);
|
||||
+
|
||||
+ /**
|
||||
+ * Unsubscribes the given Permissible for information about the requested
|
||||
@@ -134,7 +132,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param permission Permission to unsubscribe from
|
||||
+ * @param permissible Permissible subscribing
|
||||
+ */
|
||||
+ void unsubscribeFromPermission(@NotNull String permission, @NotNull Permissible permissible);
|
||||
+ void unsubscribeFromPermission(String permission, Permissible permissible);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets a set containing all subscribed {@link Permissible}s to the given
|
||||
@@ -143,8 +141,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param permission Permission to query for
|
||||
+ * @return Set containing all subscribed permissions
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ Set<Permissible> getPermissionSubscriptions(@NotNull String permission);
|
||||
+ Set<Permissible> getPermissionSubscriptions(String permission);
|
||||
+
|
||||
+ /**
|
||||
+ * Subscribes to the given Default permissions by operator status
|
||||
@@ -155,7 +152,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param op Default list to subscribe to
|
||||
+ * @param permissible Permissible subscribing
|
||||
+ */
|
||||
+ void subscribeToDefaultPerms(boolean op, @NotNull Permissible permissible);
|
||||
+ void subscribeToDefaultPerms(boolean op, Permissible permissible);
|
||||
+
|
||||
+ /**
|
||||
+ * Unsubscribes from the given Default permissions by operator status
|
||||
@@ -163,7 +160,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param op Default list to unsubscribe from
|
||||
+ * @param permissible Permissible subscribing
|
||||
+ */
|
||||
+ void unsubscribeFromDefaultPerms(boolean op, @NotNull Permissible permissible);
|
||||
+ void unsubscribeFromDefaultPerms(boolean op, Permissible permissible);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets a set containing all subscribed {@link Permissible}s to the given
|
||||
@@ -172,7 +169,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param op Default list to query for
|
||||
+ * @return Set containing all subscribed permissions
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ Set<Permissible> getDefaultPermSubscriptions(boolean op);
|
||||
+
|
||||
+ /**
|
||||
@@ -182,7 +178,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return Set containing all current registered permissions
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ Set<Permission> getPermissions();
|
||||
+
|
||||
+ /**
|
||||
@@ -192,7 +187,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @param perm permission
|
||||
+ */
|
||||
+ void addPermissions(@NotNull List<Permission> perm);
|
||||
+ void addPermissions(List<Permission> perm);
|
||||
+
|
||||
+ /**
|
||||
+ * Clears the current registered permissinos.
|
||||
@@ -211,6 +206,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+package io.papermc.paper.plugin.bootstrap;
|
||||
+
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * Represents the context provided to a {@link PluginBootstrap} during both the bootstrapping and plugin
|
||||
@@ -219,6 +215,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * like the plugin's configuration or logger during the plugins bootstrap.
|
||||
+ */
|
||||
+@ApiStatus.Experimental
|
||||
+@NullMarked
|
||||
+@ApiStatus.NonExtendable
|
||||
+public interface BootstrapContext extends PluginProviderContext {
|
||||
+}
|
||||
@@ -233,7 +230,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import io.papermc.paper.plugin.provider.util.ProviderUtil;
|
||||
+import org.bukkit.plugin.java.JavaPlugin;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * A plugin bootstrap is meant for loading certain parts of the plugin before the server is loaded.
|
||||
@@ -245,8 +242,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * <p>
|
||||
+ * <b>All calls to Bukkit may throw a NullPointerExceptions or return null unexpectedly. You should only call api methods that are explicitly documented to work in the bootstrapper</b>
|
||||
+ */
|
||||
+@ApiStatus.OverrideOnly
|
||||
+@ApiStatus.Experimental
|
||||
+@NullMarked
|
||||
+@ApiStatus.OverrideOnly
|
||||
+public interface PluginBootstrap {
|
||||
+
|
||||
+ /**
|
||||
@@ -254,7 +252,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @param context the server provided context
|
||||
+ */
|
||||
+ void bootstrap(@NotNull BootstrapContext context);
|
||||
+ void bootstrap(BootstrapContext context);
|
||||
+
|
||||
+ /**
|
||||
+ * Called by the server to instantiate your main class.
|
||||
@@ -264,8 +262,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param context the server created bootstrap object
|
||||
+ * @return the server requested instance of the plugins main class.
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ default JavaPlugin createPlugin(@NotNull PluginProviderContext context) {
|
||||
+ default JavaPlugin createPlugin(final PluginProviderContext context) {
|
||||
+ return ProviderUtil.loadClass(context.getConfiguration().getMainClass(), JavaPlugin.class, this.getClass().getClassLoader());
|
||||
+ }
|
||||
+}
|
||||
@@ -278,11 +275,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+package io.papermc.paper.plugin.bootstrap;
|
||||
+
|
||||
+import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||
+import java.nio.file.Path;
|
||||
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.nio.file.Path;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * Represents the context provided to a {@link PluginBootstrap} during both the bootstrapping and plugin
|
||||
@@ -290,8 +286,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * A bootstrap context may be used to access data or logic usually provided to {@link org.bukkit.plugin.Plugin} instances
|
||||
+ * like the plugin's configuration or logger during the plugins bootstrap.
|
||||
+ */
|
||||
+@ApiStatus.NonExtendable
|
||||
+@ApiStatus.Experimental
|
||||
+@NullMarked
|
||||
+@ApiStatus.NonExtendable
|
||||
+public interface PluginProviderContext {
|
||||
+
|
||||
+ /**
|
||||
@@ -299,7 +296,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return the plugin's configuration
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ PluginMeta getConfiguration();
|
||||
+
|
||||
+ /**
|
||||
@@ -307,7 +303,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return the previously described path
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ Path getDataDirectory();
|
||||
+
|
||||
+ /**
|
||||
@@ -315,7 +310,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return the logger instance
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ ComponentLogger getLogger();
|
||||
+
|
||||
+ /**
|
||||
@@ -323,7 +317,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return the previously described path
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ Path getPluginSource();
|
||||
+
|
||||
+}
|
||||
@@ -335,21 +328,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.plugin.configuration;
|
||||
+
|
||||
+import java.util.List;
|
||||
+import org.bukkit.permissions.Permission;
|
||||
+import org.bukkit.permissions.PermissionDefault;
|
||||
+import org.bukkit.plugin.PluginLoadOrder;
|
||||
+import org.bukkit.plugin.java.JavaPlugin;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+import java.util.List;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * This class acts as an abstraction for a plugin configuration.
|
||||
+ */
|
||||
+@ApiStatus.NonExtendable
|
||||
+@ApiStatus.Experimental // Subject to change!
|
||||
+@NullMarked
|
||||
+@ApiStatus.NonExtendable
|
||||
+public interface PluginMeta {
|
||||
+
|
||||
+ /**
|
||||
@@ -369,7 +362,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return the name of the plugin
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ String getName();
|
||||
+
|
||||
+ /**
|
||||
@@ -377,7 +369,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return a descriptive name of the plugin and respective version
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ default String getDisplayName() {
|
||||
+ return this.getName() + " v" + this.getVersion();
|
||||
+ }
|
||||
@@ -388,7 +379,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return the fully qualified class name of the plugin's main class.
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ String getMainClass();
|
||||
+
|
||||
+ /**
|
||||
@@ -397,7 +387,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @return the plugin load order
|
||||
+ * @see PluginLoadOrder for further details regards the available load orders.
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ PluginLoadOrder getLoadOrder();
|
||||
+
|
||||
+ /**
|
||||
@@ -407,7 +396,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return the string representation of the plugin's version
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ String getVersion();
|
||||
+
|
||||
+ /**
|
||||
@@ -418,8 +406,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @return the specific overwrite of the logger prefix as defined by the plugin. If the plugin did not define a
|
||||
+ * custom logger prefix, this method will return null
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ String getLoggerPrefix();
|
||||
+ @Nullable String getLoggerPrefix();
|
||||
+
|
||||
+ /**
|
||||
+ * Provides a list of dependencies that are required for this plugin to load.
|
||||
@@ -430,7 +417,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return an immutable list of required dependency names
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ List<String> getPluginDependencies();
|
||||
+
|
||||
+ /**
|
||||
@@ -443,7 +429,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return immutable list of soft dependencies
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ List<String> getPluginSoftDependencies();
|
||||
+
|
||||
+ /**
|
||||
@@ -456,7 +441,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return immutable list of plugins to load before this plugin
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ List<String> getLoadBeforePlugins();
|
||||
+
|
||||
+ /**
|
||||
@@ -466,7 +450,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return immutable list of provided plugins/dependencies
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ List<String> getProvidedPlugins();
|
||||
+
|
||||
+ /**
|
||||
@@ -475,7 +458,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return an immutable list of the plugin's authors
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ List<String> getAuthors();
|
||||
+
|
||||
+ /**
|
||||
@@ -484,7 +466,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return an immutable list of the plugin's contributors
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ List<String> getContributors();
|
||||
+
|
||||
+ /**
|
||||
@@ -493,8 +474,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return description or null if the plugin did not define a human readable description.
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ String getDescription();
|
||||
+ @Nullable String getDescription();
|
||||
+
|
||||
+ /**
|
||||
+ * Provides the website for the plugin or the plugin's author.
|
||||
@@ -502,8 +482,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return a string representation of the website that serves as the main hub for this plugin/its author.
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ String getWebsite();
|
||||
+ @Nullable String getWebsite();
|
||||
+
|
||||
+ /**
|
||||
+ * Provides the list of permissions that are defined via the plugin meta instance.
|
||||
@@ -511,7 +490,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @return an immutable list of permissions
|
||||
+ */
|
||||
+ // TODO: Do we even want this? Why not just use the bootstrapper
|
||||
+ @NotNull
|
||||
+ List<Permission> getPermissions();
|
||||
+
|
||||
+ /**
|
||||
@@ -521,7 +499,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @see #getPermissions()
|
||||
+ */
|
||||
+ // TODO: Do we even want this? Why not just use the bootstrapper
|
||||
+ @NotNull
|
||||
+ PermissionDefault getPermissionDefault();
|
||||
+
|
||||
+ /**
|
||||
@@ -532,8 +509,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @return the version string made up of the major and minor version (e.g. 1.18 or 1.19). Minor versions like 1.18.2
|
||||
+ * are unified to their major release version (in this example 1.18)
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ String getAPIVersion();
|
||||
+ @Nullable String getAPIVersion();
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/configuration/package-info.java b/src/main/java/io/papermc/paper/plugin/configuration/package-info.java
|
||||
@@ -563,14 +539,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import io.papermc.paper.plugin.loader.library.LibraryStore;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.Contract;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * A mutable builder that may be used to collect and register all {@link ClassPathLibrary} instances a
|
||||
+ * {@link PluginLoader} aims to provide to its plugin at runtime.
|
||||
+ */
|
||||
+@ApiStatus.NonExtendable
|
||||
+@ApiStatus.Experimental
|
||||
+@NullMarked
|
||||
+@ApiStatus.NonExtendable
|
||||
+public interface PluginClasspathBuilder {
|
||||
+
|
||||
+ /**
|
||||
@@ -587,11 +564,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @see io.papermc.paper.plugin.loader.library.impl.JarLibrary
|
||||
+ * @see io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ @Contract("_ -> this")
|
||||
+ PluginClasspathBuilder addLibrary(@NotNull ClassPathLibrary classPathLibrary);
|
||||
+ PluginClasspathBuilder addLibrary(ClassPathLibrary classPathLibrary);
|
||||
+
|
||||
+ @NotNull
|
||||
+ PluginProviderContext getContext();
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/loader/PluginLoader.java b/src/main/java/io/papermc/paper/plugin/loader/PluginLoader.java
|
||||
@@ -603,7 +578,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+package io.papermc.paper.plugin.loader;
|
||||
+
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * A plugin loader is responsible for creating certain aspects of a plugin before it is created.
|
||||
@@ -615,8 +590,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * It should be noted that this class will be called from a different classloader, this will cause any static values
|
||||
+ * set in this class/any other classes loaded not to persist when the plugin loads.
|
||||
+ */
|
||||
+@ApiStatus.OverrideOnly
|
||||
+@ApiStatus.Experimental
|
||||
+@NullMarked
|
||||
+@ApiStatus.OverrideOnly
|
||||
+public interface PluginLoader {
|
||||
+
|
||||
+ /**
|
||||
@@ -627,7 +603,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param classpathBuilder a mutable classpath builder that may be used to register custom runtime dependencies
|
||||
+ * for the plugin the loader was registered for.
|
||||
+ */
|
||||
+ void classloader(@NotNull PluginClasspathBuilder classpathBuilder);
|
||||
+ void classloader(PluginClasspathBuilder classpathBuilder);
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/loader/library/ClassPathLibrary.java b/src/main/java/io/papermc/paper/plugin/loader/library/ClassPathLibrary.java
|
||||
@@ -638,12 +614,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.plugin.loader.library;
|
||||
+
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * The classpath library interface represents libraries that are capable of registering themselves via
|
||||
+ * {@link #register(LibraryStore)} on any given {@link LibraryStore}.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+public interface ClassPathLibrary {
|
||||
+
|
||||
+ /**
|
||||
@@ -654,7 +631,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param store the library store instance to register this library into
|
||||
+ * @throws LibraryLoadingException if library loading failed for this classpath library
|
||||
+ */
|
||||
+ void register(@NotNull LibraryStore store) throws LibraryLoadingException;
|
||||
+ void register(LibraryStore store) throws LibraryLoadingException;
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/loader/library/LibraryLoadingException.java b/src/main/java/io/papermc/paper/plugin/loader/library/LibraryLoadingException.java
|
||||
new file mode 100644
|
||||
@@ -685,10 +662,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.plugin.loader.library;
|
||||
+
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.nio.file.Path;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * Represents a storage that stores library jars.
|
||||
@@ -699,6 +675,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @see io.papermc.paper.plugin.loader.PluginLoader
|
||||
+ */
|
||||
+@ApiStatus.Internal
|
||||
+@NullMarked
|
||||
+public interface LibraryStore {
|
||||
+
|
||||
+ /**
|
||||
@@ -706,7 +683,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @param library path to the libraries jar file on the disk
|
||||
+ */
|
||||
+ void addLibrary(@NotNull Path library);
|
||||
+ void addLibrary(Path library);
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/loader/library/impl/JarLibrary.java b/src/main/java/io/papermc/paper/plugin/loader/library/impl/JarLibrary.java
|
||||
@@ -720,10 +697,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import io.papermc.paper.plugin.loader.library.ClassPathLibrary;
|
||||
+import io.papermc.paper.plugin.loader.library.LibraryLoadingException;
|
||||
+import io.papermc.paper.plugin.loader.library.LibraryStore;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.nio.file.Files;
|
||||
+import java.nio.file.Path;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * A simple jar library implementation of the {@link ClassPathLibrary} that allows {@link io.papermc.paper.plugin.loader.PluginLoader}s to
|
||||
@@ -738,6 +714,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * <p>
|
||||
+ * The jar library implementation will error if the file does not exist at the specified path.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+public class JarLibrary implements ClassPathLibrary {
|
||||
+
|
||||
+ private final Path path;
|
||||
@@ -747,12 +724,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @param path the path, relative to the JVMs start directory.
|
||||
+ */
|
||||
+ public JarLibrary(@NotNull Path path) {
|
||||
+ public JarLibrary(final Path path) {
|
||||
+ this.path = path;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void register(@NotNull LibraryStore store) throws LibraryLoadingException {
|
||||
+ public void register(final LibraryStore store) throws LibraryLoadingException {
|
||||
+ if (Files.notExists(this.path)) {
|
||||
+ throw new LibraryLoadingException("Could not find library at " + this.path);
|
||||
+ }
|
||||
@@ -771,6 +748,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import io.papermc.paper.plugin.loader.library.ClassPathLibrary;
|
||||
+import io.papermc.paper.plugin.loader.library.LibraryLoadingException;
|
||||
+import io.papermc.paper.plugin.loader.library.LibraryStore;
|
||||
+import java.io.File;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.List;
|
||||
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
||||
+import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
+import org.eclipse.aether.RepositorySystem;
|
||||
@@ -791,14 +771,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import org.eclipse.aether.transfer.TransferCancelledException;
|
||||
+import org.eclipse.aether.transfer.TransferEvent;
|
||||
+import org.eclipse.aether.transport.http.HttpTransporterFactory;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.slf4j.Logger;
|
||||
+import org.slf4j.LoggerFactory;
|
||||
+
|
||||
+import java.io.File;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.List;
|
||||
+
|
||||
+/**
|
||||
+ * The maven library resolver acts as a resolver for yet to be resolved jar libraries that may be pulled from a
|
||||
+ * remote maven repository.
|
||||
@@ -813,12 +789,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * "central", "default", "https://repo1.maven.org/maven2/"
|
||||
+ * ).build());
|
||||
+ * }</pre>
|
||||
+ *
|
||||
+ * <p>
|
||||
+ * Plugins may create and register a {@link MavenLibraryResolver} after configuring it.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+public class MavenLibraryResolver implements ClassPathLibrary {
|
||||
+
|
||||
+ private static final Logger logger = LoggerFactory.getLogger("MavenLibraryResolver");
|
||||
+ private static final Logger LOGGER = LoggerFactory.getLogger("MavenLibraryResolver");
|
||||
+
|
||||
+ private final RepositorySystem repository;
|
||||
+ private final DefaultRepositorySystemSession session;
|
||||
@@ -834,7 +811,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * submitting the {@link MavenLibraryResolver} to the {@link io.papermc.paper.plugin.loader.PluginClasspathBuilder}.
|
||||
+ */
|
||||
+ public MavenLibraryResolver() {
|
||||
+ DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
|
||||
+ final DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
|
||||
+ locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
|
||||
+ locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
|
||||
+
|
||||
@@ -846,8 +823,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ this.session.setLocalRepositoryManager(this.repository.newLocalRepositoryManager(this.session, new LocalRepository("libraries")));
|
||||
+ this.session.setTransferListener(new AbstractTransferListener() {
|
||||
+ @Override
|
||||
+ public void transferInitiated(@NotNull TransferEvent event) throws TransferCancelledException {
|
||||
+ logger.info("Downloading {}", event.getResource().getRepositoryUrl() + event.getResource().getResourceName());
|
||||
+ public void transferInitiated(final TransferEvent event) throws TransferCancelledException {
|
||||
+ LOGGER.info("Downloading {}", event.getResource().getRepositoryUrl() + event.getResource().getResourceName());
|
||||
+ }
|
||||
+ });
|
||||
+ this.session.setReadOnly();
|
||||
@@ -860,7 +837,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param dependency the definition of the dependency the maven library resolver should resolve when running
|
||||
+ * @see MavenLibraryResolver#addRepository(RemoteRepository)
|
||||
+ */
|
||||
+ public void addDependency(@NotNull Dependency dependency) {
|
||||
+ public void addDependency(final Dependency dependency) {
|
||||
+ this.dependencies.add(dependency);
|
||||
+ }
|
||||
+
|
||||
@@ -870,9 +847,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * repository.
|
||||
+ *
|
||||
+ * @param remoteRepository the configuration that defines the maven repository this library resolver should fetch
|
||||
+ * dependencies from
|
||||
+ * dependencies from
|
||||
+ */
|
||||
+ public void addRepository(@NotNull RemoteRepository remoteRepository) {
|
||||
+ public void addRepository(final RemoteRepository remoteRepository) {
|
||||
+ this.repositories.add(remoteRepository);
|
||||
+ }
|
||||
+
|
||||
@@ -883,18 +860,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @throws LibraryLoadingException if resolving a dependency failed
|
||||
+ */
|
||||
+ @Override
|
||||
+ public void register(@NotNull LibraryStore store) throws LibraryLoadingException {
|
||||
+ List<RemoteRepository> repos = this.repository.newResolutionRepositories(this.session, this.repositories);
|
||||
+ public void register(final LibraryStore store) throws LibraryLoadingException {
|
||||
+ final List<RemoteRepository> repos = this.repository.newResolutionRepositories(this.session, this.repositories);
|
||||
+
|
||||
+ DependencyResult result;
|
||||
+ final DependencyResult result;
|
||||
+ try {
|
||||
+ result = this.repository.resolveDependencies(this.session, new DependencyRequest(new CollectRequest((Dependency) null, this.dependencies, repos), null));
|
||||
+ } catch (DependencyResolutionException ex) {
|
||||
+ } catch (final DependencyResolutionException ex) {
|
||||
+ throw new LibraryLoadingException("Error resolving libraries", ex);
|
||||
+ }
|
||||
+
|
||||
+ for (ArtifactResult artifact : result.getArtifactResults()) {
|
||||
+ File file = artifact.getArtifact().getFile();
|
||||
+ for (final ArtifactResult artifact : result.getArtifactResults()) {
|
||||
+ final File file = artifact.getArtifact().getFile();
|
||||
+ store.addLibrary(file.toPath());
|
||||
+ }
|
||||
+ }
|
||||
@@ -908,7 +885,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+package io.papermc.paper.plugin.provider.classloader;
|
||||
+
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * The class loader access interface is an <b>internal</b> representation of a class accesses' ability to see types
|
||||
@@ -919,6 +896,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * is owned by a direct or transitive dependency of the plugin, preventing the plugin for accidentally discovering and
|
||||
+ * using class types that are supplied by plugins/libraries the plugin did not actively define as a dependency.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+@ApiStatus.Internal
|
||||
+public interface ClassLoaderAccess {
|
||||
+
|
||||
@@ -948,12 +926,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+package io.papermc.paper.plugin.provider.classloader;
|
||||
+
|
||||
+import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||
+import java.io.Closeable;
|
||||
+import org.bukkit.plugin.java.JavaPlugin;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.io.Closeable;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * The configured plugin class loader represents an <b>internal</b> abstraction over the classloaders used by the server
|
||||
@@ -962,6 +939,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * It implements {@link Closeable} to define the ability to shutdown and close the classloader that implements this
|
||||
+ * interface.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+@ApiStatus.Internal
|
||||
+public interface ConfiguredPluginClassLoader extends Closeable {
|
||||
+
|
||||
@@ -987,7 +965,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @see ClassLoader#loadClass(String)
|
||||
+ * @see Class#forName(String, boolean, ClassLoader)
|
||||
+ */
|
||||
+ Class<?> loadClass(@NotNull String name,
|
||||
+ Class<?> loadClass(String name,
|
||||
+ boolean resolve,
|
||||
+ boolean checkGlobal,
|
||||
+ boolean checkLibraries) throws ClassNotFoundException;
|
||||
@@ -1013,8 +991,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * that is used by the underlying classloader
|
||||
+ * @return classloader
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ PluginClassLoaderGroup getGroup();
|
||||
+ @Nullable PluginClassLoaderGroup getGroup();
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/classloader/PaperClassLoaderStorage.java b/src/main/java/io/papermc/paper/plugin/provider/classloader/PaperClassLoaderStorage.java
|
||||
new file mode 100644
|
||||
@@ -1147,7 +1124,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.Contract;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * A plugin classloader group represents a group of classloaders that a plugins classloader may access.
|
||||
@@ -1155,6 +1133,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * An example of this would be a classloader group that holds all direct and transitive dependencies a plugin declared,
|
||||
+ * allowing a plugins classloader to access classes included in these dependencies via this group.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+@ApiStatus.Internal
|
||||
+public interface PluginClassLoaderGroup {
|
||||
+
|
||||
@@ -1172,8 +1151,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * will be returned.
|
||||
+ * @see ConfiguredPluginClassLoader#loadClass(String, boolean, boolean, boolean)
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ Class<?> getClassByName(String name, boolean resolve, ConfiguredPluginClassLoader requester);
|
||||
+ @Nullable Class<?> getClassByName(String name, boolean resolve, ConfiguredPluginClassLoader requester);
|
||||
+
|
||||
+ /**
|
||||
+ * Removes a configured plugin classloader from this class loader group.
|
||||
@@ -1218,7 +1196,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * A dependency context is a read-only abstraction of a type/concept that can resolve dependencies between plugins.
|
||||
@@ -1226,6 +1204,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * This may for example be the server wide plugin manager itself, capable of validating if a dependency exists between
|
||||
+ * two {@link PluginMeta} instances, however the implementation is not limited to such a concrete use-case.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+@ApiStatus.Internal
|
||||
+public interface DependencyContext {
|
||||
+
|
||||
@@ -1245,7 +1224,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param depend the potential transitive dependency of the {@code plugin} parameter.
|
||||
+ * @return a simple boolean flag indicating if {@code plugin} considers {@code depend} as a transitive dependency.
|
||||
+ */
|
||||
+ boolean isTransitiveDependency(@NotNull PluginMeta plugin, @NotNull PluginMeta depend);
|
||||
+ boolean isTransitiveDependency(PluginMeta plugin, PluginMeta depend);
|
||||
+
|
||||
+ /**
|
||||
+ * Computes if this dependency context is aware of a dependency that provides/matches the passed identifier.
|
||||
@@ -1259,7 +1238,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @return a plain boolean flag indicating if this dependency context is aware of a potential dependency with the
|
||||
+ * passed identifier.
|
||||
+ */
|
||||
+ boolean hasDependency(@NotNull String pluginIdentifier);
|
||||
+ boolean hasDependency(String pluginIdentifier);
|
||||
+
|
||||
+}
|
||||
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
|
||||
@@ -1272,16 +1251,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+import com.destroystokyo.paper.util.SneakyThrow;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * An <b>internal</b> utility type that holds logic for loading a provider-like type from a classloaders.
|
||||
+ * Provides, at least in the context of this utility, define themselves as implementations of a specific parent
|
||||
+ * interface/type, e.g. {@link org.bukkit.plugin.java.JavaPlugin} and implement a no-args constructor.
|
||||
+ */
|
||||
+@NullMarked
|
||||
+@ApiStatus.Internal
|
||||
+public class ProviderUtil {
|
||||
+public final class ProviderUtil {
|
||||
+
|
||||
+ /**
|
||||
+ * Loads the class found at the provided fully qualified class name from the passed classloader, creates a new
|
||||
@@ -1294,8 +1274,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param <T> the generic type of the parent class the created object will be cast to
|
||||
+ * @return the object instantiated from the class found at the provided FQN, cast to the parent type
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public static <T> T loadClass(@NotNull String clazz, @NotNull Class<T> classType, @NotNull ClassLoader loader) {
|
||||
+ public static <T> T loadClass(final String clazz, final Class<T> classType, final ClassLoader loader) {
|
||||
+ return loadClass(clazz, classType, loader, null);
|
||||
+ }
|
||||
+
|
||||
@@ -1312,30 +1291,29 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @return the object instantiated from the class found at the provided fully qualified class name, cast to the
|
||||
+ * parent type
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public static <T> T loadClass(@NotNull String clazz, @NotNull Class<T> classType, @NotNull ClassLoader loader, @Nullable Runnable onError) {
|
||||
+ public static <T> T loadClass(final String clazz, final Class<T> classType, final ClassLoader loader, final @Nullable Runnable onError) {
|
||||
+ try {
|
||||
+ T clazzInstance;
|
||||
+ final T clazzInstance;
|
||||
+
|
||||
+ try {
|
||||
+ Class<?> jarClass = Class.forName(clazz, true, loader);
|
||||
+ final Class<?> jarClass = Class.forName(clazz, true, loader);
|
||||
+
|
||||
+ Class<? extends T> pluginClass;
|
||||
+ final Class<? extends T> pluginClass;
|
||||
+ try {
|
||||
+ pluginClass = jarClass.asSubclass(classType);
|
||||
+ } catch (ClassCastException ex) {
|
||||
+ } catch (final ClassCastException ex) {
|
||||
+ throw new ClassCastException("class '%s' does not extend '%s'".formatted(clazz, classType));
|
||||
+ }
|
||||
+
|
||||
+ clazzInstance = pluginClass.getDeclaredConstructor().newInstance();
|
||||
+ } catch (IllegalAccessException exception) {
|
||||
+ } catch (final IllegalAccessException exception) {
|
||||
+ throw new RuntimeException("No public constructor");
|
||||
+ } catch (InstantiationException exception) {
|
||||
+ } catch (final InstantiationException exception) {
|
||||
+ throw new RuntimeException("Abnormal class instantiation", exception);
|
||||
+ }
|
||||
+
|
||||
+ return clazzInstance;
|
||||
+ } catch (Throwable e) {
|
||||
+ } catch (final Throwable e) {
|
||||
+ if (onError != null) {
|
||||
+ onError.run();
|
||||
+ }
|
||||
|
Reference in New Issue
Block a user