Package dev.cwhead.GravesX.module
Class ModuleManager
java.lang.Object
dev.cwhead.GravesX.module.ModuleManager
Manages GravesX modules: discovers, loads, resolves order, and enables/disables them.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classController exposed to modules viaModuleContext.getGravesXModules().private static final classRead-only adapter that exposes a module'smodule.ymlmetadata and current runtime state viaGravesXModuleDescriptor.static final classHolds a loaded module instance and its metadata. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ModuleCommandRegistrarprivate LibraryImporterprivate final Map<String, ModuleManager.LoadedModule> private final Loggerprivate final Fileprivate final Graves -
Constructor Summary
ConstructorsConstructorDescriptionModuleManager(Graves plugin) Creates a manager bound to the given plugin and ensures the modules directory exists. -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanAttempts to enable the given loaded module, checking plugin and module dependencies.private voidComputes a topological order across module dependencies and soft constraints.private voiddebug(ModuleInfo mi, String m, int num) Logs a debug-level message with the modules name as the prefix and a debug type.private voidLogs a debug-level message with a modules prefix and a debug type.private booleanDisables and unloads a specific module by name.voidDisables all modules in reverse topological order.Scan module jars and collect all external Bukkit plugin names that modules declare via pluginDepends and pluginSoftDepends, without loading classes.private booleanEnables a specific module by name.voidEnables all modules in topological order.private ModuleManager.LoadedModuleCase-insensitive match by module.yml name, simple class name, or FQCN.Looks up a loaded module by name.Collects required Bukkit plugins that exist but are currently disabled.private voidinfo(ModuleInfo mi, String m) Logs an info-level message with the modules name as the prefix.private voidLogs an info-level message with a modules prefix.voidloadAll()Scans the modules directory, validates jars, loads metadata, constructs instances, and calls onModuleLoad.Collects required Bukkit plugins that are not installed (null from PluginManager).modules()Gets all loaded modules.private static Stringorder()Returns the computed topological load order.pending()Returns the set of modules waiting on missing requirements.voidsetLibraryImporter(LibraryImporter importer) Sets the library importer used by modules to resolve external libraries.private voidsevere(ModuleInfo mi, String m, Throwable t) Logs a severe-level message with the modules name as the prefix and a throwable.private voidLogs a severe-level message with a modules prefix and a throwable.booleanTrue if any plugin referenced by any module is present on the server.voidAttempts to enable modules currently pending if their requirements are now met.private voidwarn(ModuleInfo mi, String m) Logs a warning-level message with the modules name as the prefix.private voidLogs a warning-level message with a modules prefix.
-
Field Details
-
plugin
-
logger
-
modulesDir
-
importer
-
loaded
-
pending
-
topoOrder
-
commandRegistrar
-
-
Constructor Details
-
ModuleManager
Creates a manager bound to the given plugin and ensures the modules directory exists.- Parameters:
plugin- Owning plugin.
-
-
Method Details
-
setLibraryImporter
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
Returns the computed topological load order.- Returns:
- List of module names in load order.
-
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
Enables a specific module by name.- Parameters:
name- Module name.- Returns:
- True if already enabled or enabled successfully.
-
disable
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
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
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
Collects required Bukkit plugins that are not installed (null from PluginManager).- Parameters:
info- Module metadata.- Returns:
- List of missing plugin names.
-
inactiveRequiredPlugins
Collects required Bukkit plugins that exist but are currently disabled.- Parameters:
info- Module metadata.- Returns:
- List of inactive plugin names.
-
findByKey
Case-insensitive match by module.yml name, simple class name, or FQCN. -
norm
-
info
Logs an info-level message with a modules prefix.- Parameters:
m- Message to log.
-
info
Logs an info-level message with the modules name as the prefix.- Parameters:
mi- The module infom- Message to log.
-
warn
Logs a warning-level message with a modules prefix.- Parameters:
m- Message to log.
-
warn
Logs a warning-level message with the modules name as the prefix.- Parameters:
mi- The module infom- Message to log.
-
severe
Logs a severe-level message with a modules prefix and a throwable.- Parameters:
m- Message to log.t- Throwable to include.
-
severe
Logs a severe-level message with the modules name as the prefix and a throwable.- Parameters:
mi- The module infom- Message to log.t- Throwable to include.
-
debug
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
Logs a debug-level message with the modules name as the prefix and a debug type.- Parameters:
mi- The module infom- Message to log.num- Debug number (1 info, 2 error/failure).
-