Interface PaperClassLoaderStorage


@Internal public interface PaperClassLoaderStorage
The plugin classloader storage is an internal type that is used to manage existing classloaders on the server.

The paper classloader storage is also responsible for storing added ConfiguredPluginClassLoaders into PluginClassLoaderGroups, via registerOpenGroup(ConfiguredPluginClassLoader), registerSpigotGroup(PluginClassLoader) and registerAccessBackedGroup(ConfiguredPluginClassLoader, ClassLoaderAccess).

Groups are differentiated into the global group or plugin owned groups.

  • The global group holds all registered class loaders and merely exists to maintain backwards compatibility with spigots legacy classloader handling.
  • The plugin groups only contains the classloaders that each plugin has access to and hence serves to properly separates unrelated classloaders.
  • Method Details

    • instance

      static PaperClassLoaderStorage instance()
      Access to the shared instance of the PaperClassLoaderStorageAccess.
      Returns:
      the singleton instance of the PaperClassLoaderStorage used throughout the server
    • registerSpigotGroup

      PluginClassLoaderGroup registerSpigotGroup(PluginClassLoader pluginClassLoader)
      Registers a legacy spigot PluginClassLoader into the loader storage, creating a group wrapping the single plugin class loader with transitive access to the global group.
      Parameters:
      pluginClassLoader - the legacy spigot plugin class loader to register
      Returns:
      the group the plugin class loader was placed into
    • registerOpenGroup

      PluginClassLoaderGroup registerOpenGroup(ConfiguredPluginClassLoader classLoader)
      Registers a paper configured plugin classloader into a new open group, with full access to the global plugin class loader group.

      This method hence allows the configured plugin class loader to access all other class loaders registered in this storage.

      Parameters:
      classLoader - the configured plugin class loader to register
      Returns:
      the group the plugin class loader was placed into
    • registerAccessBackedGroup

      PluginClassLoaderGroup registerAccessBackedGroup(ConfiguredPluginClassLoader classLoader, ClassLoaderAccess access)
      Registers a paper configured classloader into a new, access backed group. The access backed classloader group, different from an open group, only has access to the classloaders the passed ClassLoaderAccess grants access to.
      Parameters:
      classLoader - the configured plugin class loader to register
      access - the class loader access that defines what other classloaders the passed plugin class loader should be granted access to.
      Returns:
      the group the plugin class loader was placed into.
    • unregisterClassloader

      void unregisterClassloader(ConfiguredPluginClassLoader configuredPluginClassLoader)
      Unregisters a configured class loader from this storage. This removes the passed class loaders from any group it may have been a part of, including the global group.

      Note: this method is highly discouraged from being used, as mutation of the classloaders at runtime is not encouraged

      Parameters:
      configuredPluginClassLoader - the class loader to remove from this storage.
    • registerUnsafePlugin

      boolean registerUnsafePlugin(ConfiguredPluginClassLoader pluginLoader)
      Registers a configured plugin class loader directly into the global group without adding it to any existing groups.

      Note: this method unsafely injects the plugin classloader directly into the global group, which bypasses the group structure paper's plugin API introduced. This method should hence be used with caution.

      Parameters:
      pluginLoader - the configured plugin classloader instance that should be registered directly into the global group.
      Returns:
      a simple boolean flag, true if the classloader was registered or false if the classloader was already part of the global group.