Class ProviderUtil
java.lang.Object
io.papermc.paper.plugin.provider.util.ProviderUtil
An internal 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.
JavaPlugin
and implement a no-args constructor.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
Loads the class found at the provided fully qualified class name from the passed classloader, creates a new instance of it using the no-args constructor, that should exist as per this method contract, and casts it to the provided parent type.static <T> T
loadClass
(@NotNull String clazz, @NotNull Class<T> classType, @NotNull ClassLoader loader, @Nullable Runnable onError) Loads the class found at the provided fully qualified class name from the passed classloader, creates a new instance of it using the no-args constructor, that should exist as per this method contract, and casts it to the provided parent type.
-
Constructor Details
-
ProviderUtil
public ProviderUtil()
-
-
Method Details
-
loadClass
@NotNull public static <T> T loadClass(@NotNull @NotNull String clazz, @NotNull @NotNull Class<T> classType, @NotNull @NotNull ClassLoader loader) Loads the class found at the provided fully qualified class name from the passed classloader, creates a new instance of it using the no-args constructor, that should exist as per this method contract, and casts it to the provided parent type.- Type Parameters:
T
- the generic type of the parent class the created object will be cast to- Parameters:
clazz
- the fully qualified name of the class to loadclassType
- the parent type that the created object found at theclazz
name should be cast toloader
- the loader from which the class should be loaded- Returns:
- the object instantiated from the class found at the provided FQN, cast to the parent type
-
loadClass
@NotNull public static <T> T loadClass(@NotNull @NotNull String clazz, @NotNull @NotNull Class<T> classType, @NotNull @NotNull ClassLoader loader, @Nullable @Nullable Runnable onError) Loads the class found at the provided fully qualified class name from the passed classloader, creates a new instance of it using the no-args constructor, that should exist as per this method contract, and casts it to the provided parent type.- Type Parameters:
T
- the generic type of the parent class the created object will be cast to- Parameters:
clazz
- the fully qualified name of the class to loadclassType
- the parent type that the created object found at theclazz
name should be cast toloader
- the loader from which the class should be loadedonError
- a runnable that is executed before any unknown exception is raised through a sneaky throw.- Returns:
- the object instantiated from the class found at the provided fully qualified class name, cast to the parent type
-