Class ModuleManager

java.lang.Object
dev.cwhead.GravesX.module.ModuleManager

public final class ModuleManager extends Object
Manages GravesX modules: discovers, loads, resolves order, and enables/disables them.

Module metadata is parsed from module.yml into ModuleInfo, including the supportsFolia flag, load phase, and optional libraries list, which are then exposed via GravesXModuleDescriptor.

  • Constructor Details

    • ModuleManager

      public ModuleManager(Graves plugin)
      Creates a manager bound to the given plugin and ensures the modules directory exists.
      Parameters:
      plugin - Owning plugin.
  • Method Details

    • setLibraryImporter

      public void setLibraryImporter(LibraryImporter importer)
      Sets the library importer used by modules to resolve external libraries.
      Parameters:
      importer - Library importer to use.
    • modules

      Gets all loaded modules.
      Returns:
      Unmodifiable view of loaded modules.
    • get

      Looks up a loaded module by name.
      Parameters:
      name - Module name.
      Returns:
      Optional containing the module if present.
    • order

      public List<String> order()
      Returns the computed topological load order.
      Returns:
      List of module names in load order.
    • pending

      public Set<String> pending()
      Returns the set of modules waiting on missing requirements.
      Returns:
      Unmodifiable set of pending module names.
    • loadAll

      public void loadAll()
      Scans the modules directory, validates jars, loads metadata, constructs instances, imports declared module libraries (if any), and calls GravesXModule.onModuleLoad(ModuleContext).

      Also computes the topological order after loading descriptors.

    • enableAll

      public void enableAll(GravesXModuleController.LoadPhase phase)
      Enables all modules in topological order.
    • enableAll

      public void enableAll()
    • tryEnablePending

      public void tryEnablePending()
      Attempts to enable modules currently pending if their requirements are now met.
    • enable

      public boolean enable(String name)
      Enables a specific module by name.
      Parameters:
      name - Module name.
      Returns:
      True if already enabled or enabled successfully.
    • enable

      public boolean enable(Class<? extends GravesXModule> moduleClass)
      Enables a specific module by its class (GravesXModule extender).
      Parameters:
      moduleClass - Class of the module to enable.
      Returns:
      True if already enabled or enabled successfully.
    • enable

      public boolean enable(GravesXModule module)
      Enables a specific module by its instance (GravesXModule extender).
      Parameters:
      module - GravesXModule instance.
      Returns:
      True if already enabled or enabled successfully.
    • disable

      public boolean disable(String name)
      Disables and unloads a specific module by name.
      Parameters:
      name - Module name.
      Returns:
      True if disabled, false if not found.
    • disable

      public boolean disable(Class<? extends GravesXModule> moduleClass)
      Disables and unloads a specific module by its class (GravesXModule extender).
      Parameters:
      moduleClass - Class of the module to disable.
      Returns:
      True if disabled, false if not found.
    • disable

      public boolean disable(GravesXModule module)
      Disables and unloads a specific module by its instance (GravesXModule extender).
      Parameters:
      module - GravesXModule instance.
      Returns:
      True if disabled, false if not found.
    • disableAll

      public void disableAll()
      Disables all modules in reverse topological order.
    • detectModules

      public List<ModuleInfo> detectModules()
      Scans the modules directory and returns a lightweight list of detected modules by reading only module.yml from each jar (no class loading).
    • discoverExternalPluginHints

      public Set<String> discoverExternalPluginHints()
      Scan module jars and collect all external Bukkit plugin names that modules declare via pluginDepends and pluginSoftDepends, without loading classes.
    • shouldDeferLoadOnExternalPlugins

      public boolean shouldDeferLoadOnExternalPlugins()
      True if any plugin referenced by any module is present on the server. If true, we defer module load to onEnable so those plugins are fully initialized.