Class ProviderUtil

java.lang.Object
io.papermc.paper.plugin.provider.util.ProviderUtil

@Internal public class ProviderUtil extends Object
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 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 load
      classType - the parent type that the created object found at the clazz name should be cast to
      loader - 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 load
      classType - the parent type that the created object found at the clazz name should be cast to
      loader - the loader from which the class should be loaded
      onError - 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