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.
  • Field Details

  • 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, and calls onModuleLoad. Also computes the topological order after loading descriptors.
    • buildTopoOrder

      private void buildTopoOrder()
      Computes a topological order across module dependencies and soft constraints. Falls back to a partial order if cycles are detected.
    • enableAll

      public void enableAll()
      Enables all modules in topological order.
    • tryEnablePending

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

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

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

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

      private boolean attemptEnable(ModuleManager.LoadedModule lm)
      Attempts to enable the given loaded module, checking plugin and module dependencies. On failure, it logs, cleans up, and unloads the module.
      Parameters:
      lm - Loaded module bundle.
      Returns:
      True if enabled successfully.
    • 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.
    • missingRequiredPlugins

      private List<String> missingRequiredPlugins(ModuleInfo info)
      Collects required Bukkit plugins that are not installed (null from PluginManager).
      Parameters:
      info - Module metadata.
      Returns:
      List of missing plugin names.
    • inactiveRequiredPlugins

      private List<String> inactiveRequiredPlugins(ModuleInfo info)
      Collects required Bukkit plugins that exist but are currently disabled.
      Parameters:
      info - Module metadata.
      Returns:
      List of inactive plugin names.
    • findByKey

      private ModuleManager.LoadedModule findByKey(String key)
      Case-insensitive match by module.yml name, simple class name, or FQCN.
    • norm

      private static String norm(String s)
    • info

      private void info(String m)
      Logs an info-level message with a modules prefix.
      Parameters:
      m - Message to log.
    • info

      private void info(ModuleInfo mi, String m)
      Logs an info-level message with the modules name as the prefix.
      Parameters:
      mi - The module info
      m - Message to log.
    • warn

      private void warn(String m)
      Logs a warning-level message with a modules prefix.
      Parameters:
      m - Message to log.
    • warn

      private void warn(ModuleInfo mi, String m)
      Logs a warning-level message with the modules name as the prefix.
      Parameters:
      mi - The module info
      m - Message to log.
    • severe

      private void severe(String m, Throwable t)
      Logs a severe-level message with a modules prefix and a throwable.
      Parameters:
      m - Message to log.
      t - Throwable to include.
    • severe

      private void severe(ModuleInfo mi, String m, Throwable t)
      Logs a severe-level message with the modules name as the prefix and a throwable.
      Parameters:
      mi - The module info
      m - Message to log.
      t - Throwable to include.
    • debug

      private void debug(String m, int num)
      Logs a debug-level message with a modules prefix and a debug type.
      Parameters:
      m - Message to log.
      num - Debug number (1 info, 2 error/failure).
    • debug

      private void debug(ModuleInfo mi, String m, int num)
      Logs a debug-level message with the modules name as the prefix and a debug type.
      Parameters:
      mi - The module info
      m - Message to log.
      num - Debug number (1 info, 2 error/failure).