Class ProviderUtil

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

@NullMarked @Internal public final 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 Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    loadClass(String clazz, Class<T> classType, 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.
    static <T> T
    loadClass(String clazz, Class<T> classType, 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ProviderUtil

      public ProviderUtil()
  • Method Details

    • loadClass

      public static <T> T loadClass(String clazz, Class<T> classType, 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

      public static <T> T loadClass(String clazz, Class<T> classType, 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.
      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