Class PluginClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class PluginClassLoader extends URLClassLoader
A class loader used to load plugin classes from JavaPlugin instances
  • Constructor Details

    • PluginClassLoader

      public PluginClassLoader(@Nonnull PluginManager pluginManager, @Nullable PluginIdentifier identifier, boolean inServerClassPath, @Nonnull URL... urls)
      Default Constructor for a PluginClassLoader instance
      Parameters:
      pluginManager - The affiliated plugin manager
      identifier - Optional identifier of the plugin that owns this classloader
      inServerClassPath - Whether the plugin is within the server class path
      urls - Additional URLs that should be considered
    • PluginClassLoader

      public PluginClassLoader(@Nonnull PluginManager pluginManager, @Nullable PluginIdentifier identifier, boolean inServerClassPath, boolean childFirst, @Nonnull URL... urls)
      Constructor for a PluginClassLoader instance with child-first class loading support.
      Parameters:
      pluginManager - The affiliated plugin manager
      identifier - Optional identifier of the plugin that owns this classloader
      inServerClassPath - Whether the plugin is within the server class path
      childFirst - When true, loads classes from own URLs before the server classloader
      urls - Additional URLs that should be considered
  • Method Details

    • isInServerClassPath

      public boolean isInServerClassPath()
      Returns:
      true if the plugin is within the server class path, false otherwise
    • loadLocalClass

      @Nonnull public Class<?> loadLocalClass(@Nonnull String name) throws ClassNotFoundException
      Loads the classes of the currently set plugin
      Parameters:
      name - The name of the main class that we are loading from
      Returns:
      the loaded JavaPlugin instance
      Throws:
      ClassNotFoundException - Thrown if no class was found from any of the attempted loads
    • getResource

      @Nullable public URL getResource(@Nonnull String name)
      Overrides:
      getResource in class ClassLoader
    • getResources

      @Nonnull public Enumeration<URL> getResources(@Nonnull String name) throws IOException
      Overrides:
      getResources in class ClassLoader
      Throws:
      IOException
    • isFromThirdPartyPlugin

      public static boolean isFromThirdPartyPlugin(@Nullable Throwable throwable)
      Checks if an exception originated from a third-party plugin by examining the stack trace and classloader hierarchy. Used as a fallback filter for exceptions that bypass plugin loggers.