Class InitializersPluginLoader<T>

java.lang.Object
net.regsirius06.engine.plugins.loaders.InitializersPluginLoader<T>
Type Parameters:
T - the type of objects that this initializer will create or manage
All Implemented Interfaces:
PluginLoader<Initializer<T>>
Direct Known Subclasses:
LabyrinthPanelsPluginLoader

public abstract class InitializersPluginLoader<T> extends Object implements PluginLoader<Initializer<T>>
A plugin loader implementation for loading Initializer plugins of a specific type T.

This class uses the ServiceLoader mechanism to load plugins of type Initializer for a specified type T, both from the system's service provider and from additional plugins specified via the AddTo annotation. It ensures that plugins are loaded for a specific core type provided during initialization.

The loader is capable of filtering plugins that are compatible with the type T and ensures that plugins with the matching type are loaded into the system. The loader also logs information about the loaded plugins using the SLF4J logging framework.

  • Field Details

    • log

      public static final org.slf4j.Logger log
      Logger instance for logging plugin loading operations, errors, and status updates.

      This logger is used to record key events in the plugin loading lifecycle, including:

      • The successful loading of Initializer plugins, with their class names being logged as informational messages.
      • Errors related to plugin loading, such as when no plugins are available or when a specific plugin cannot be found by its class name.

      The logger uses the SLF4J logging framework, allowing for flexible logging configurations, such as different logging levels (INFO, ERROR, etc.), output destinations, and formats. This makes it suitable for both development and production environments.

      Example log outputs:

      • Informational log when a plugin is successfully loaded: "Loaded class: plugin-class-name"
      • Error log when no plugins are available: "No available plugins."
      • Error log when a plugin is not found by its class name: "Plugin \"plugin-class-name\" not found."

      Using this log, developers can track which plugins are loaded, debug issues with missing plugins, and ensure that the plugin system operates as expected during runtime.

  • Constructor Details

    • InitializersPluginLoader

      public InitializersPluginLoader(@NotNull @NotNull Class<T> initializerType, @NotNull @NotNull Class<? extends Core> coreType)
      Constructs a new InitializersPluginLoader for the given initializer type and core type.

      This constructor initializes the loader and automatically loads the plugins using the loadPlugins() method.

      Parameters:
      initializerType - the type of initializer to load
      coreType - the core type to associate with the loader
  • Method Details

    • loadPlugins

      public void loadPlugins()
      Loads all available Initializer plugins of type T using the ServiceLoader mechanism.

      This method first clears any previously loaded plugins, then loads plugins from the service provider configured for the core type. It also loads plugins that are marked with the AddTo annotation and belong to the same core as the current plugin type.

      After loading, the method logs the names of the loaded plugin classes using SLF4J.

      Specified by:
      loadPlugins in interface PluginLoader<T>
    • getPlugins

      public List<Initializer<T>> getPlugins()
      Returns the list of all currently loaded Initializer plugins.
      Specified by:
      getPlugins in interface PluginLoader<T>
      Returns:
      a list of plugins of type Initializer<T>
    • getPlugin

      @Nullable public @Nullable Initializer<T> getPlugin(String id)
      Retrieves a specific initializer plugin by its unique class name.

      The plugin is identified by its fully qualified class name, which is usually obtained via Class.getName().

      Specified by:
      getPlugin in interface PluginLoader<T>
      Parameters:
      id - the fully qualified class name of the initializer plugin to retrieve
      Returns:
      the initializer plugin associated with the given class name, or null if not found