Package dev.cwhead.GravesX.module
Class ModuleContext
java.lang.Object
dev.cwhead.GravesX.module.ModuleContext
Provides services and utilities to a single module: data folder, logging,
config handling, resource I/O, event/task/service registration, and cleanup.
-
Constructor Summary
ConstructorsConstructorDescriptionModuleContext
(Graves plugin, String moduleName, ClassLoader moduleClassLoader, LibraryImporter importer) Creates a context for a module and prepares its storage and config. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addShutdownHook
(Runnable hook) Adds a hook to be invoked during cleanup.Gets the module's class loader.org.bukkit.configuration.file.FileConfiguration
Gets the YAML configuration, loading it if not already loaded.Gets the module-specific data folder.Exposes the per-module controller for enable/disable/isEnabled access.Gets the logger to use for this module.Gets this module's name.Gets the owning Graves plugin.void
importLibrary
(String coordinates) Imports external libraries for this module using the configured importer.<T extends AutoCloseable>
TregisterCloseable
(T closeable) Registers a closeable resource to be closed during cleanup.<T extends org.bukkit.event.Listener>
TregisterListener
(T listener) Registers an event listener and tracks it for automatic cleanup.<T> void
registerService
(Class<T> service, T provider, org.bukkit.plugin.ServicePriority prio) Registers a Bukkit service and tracks it for automatic unregister.void
Reloads the configuration from disk and applies default values from resources.void
Schedules a synchronous task using the GravesX scheduler.void
Schedules an asynchronous task using the GravesX scheduler.void
runTaskLater
(Runnable r, long delay) Schedules a delayed synchronous task using the GravesX scheduler.void
runTaskTimer
(Runnable r, long delay, long period) Schedules a repeating synchronous task using the GravesX scheduler.void
runTaskTimerAsync
(Runnable r, long delay, long period) Schedules a repeating asynchronous task using the GravesX scheduler.void
Saves the current configuration to disk.void
Copies all default YAML resources (except module.yml) from the module JAR into this module's data folder, preserving subfolders.void
saveResource
(String path, boolean replace) Saves an embedded resource from the module jar into the module data folder.
-
Constructor Details
-
ModuleContext
public ModuleContext(Graves plugin, String moduleName, ClassLoader moduleClassLoader, LibraryImporter importer) Creates a context for a module and prepares its storage and config.- Parameters:
plugin
- Owning Graves plugin.moduleName
- Module name used for paths and messages.moduleClassLoader
- Class loader that serves module resources.importer
- Library importer used byimportLibrary(String)
.
-
-
Method Details
-
getPlugin
Gets the owning Graves plugin.- Returns:
- Plugin instance.
-
getModuleName
Gets this module's name.- Returns:
- Module name.
-
getDataFolder
Gets the module-specific data folder.- Returns:
- Data folder path.
-
getLogger
Gets the logger to use for this module.- Returns:
- Logger instance.
-
getClassLoader
Gets the module's class loader.- Returns:
- Class loader serving module resources.
-
saveDefaultConfig
public void saveDefaultConfig()Copies all default YAML resources (except module.yml) from the module JAR into this module's data folder, preserving subfolders. Existing files are not overwritten. Ensures a config.yml exists (copy or stub), then reloads the config. -
getConfig
public org.bukkit.configuration.file.FileConfiguration getConfig()Gets the YAML configuration, loading it if not already loaded.- Returns:
- Configuration handle.
-
saveConfig
public void saveConfig()Saves the current configuration to disk. -
reloadConfig
public void reloadConfig()Reloads the configuration from disk and applies default values from resources. -
saveResource
Saves an embedded resource from the module jar into the module data folder.- Parameters:
path
- Resource path inside the jar.replace
- If true, overwrites an existing file.
-
registerListener
public <T extends org.bukkit.event.Listener> T registerListener(T listener) Registers an event listener and tracks it for automatic cleanup.- Type Parameters:
T
- Listener type.- Parameters:
listener
- Listener to register.- Returns:
- The same listener for chaining.
-
runTask
Schedules a synchronous task using the GravesX scheduler.- Parameters:
r
- Task to run.
-
runTaskLater
Schedules a delayed synchronous task using the GravesX scheduler.- Parameters:
r
- Task to run.delay
- Delay in ticks before first run.
-
runTaskTimer
Schedules a repeating synchronous task using the GravesX scheduler.- Parameters:
r
- Task to run.delay
- Delay in ticks before first run.period
- Period in ticks between runs.
-
runTaskAsync
Schedules an asynchronous task using the GravesX scheduler.- Parameters:
r
- Task to run.
-
runTaskTimerAsync
Schedules a repeating asynchronous task using the GravesX scheduler.- Parameters:
r
- Task to run.delay
- Delay in ticks before first run.period
- Period in ticks between runs.
-
registerService
public <T> void registerService(Class<T> service, T provider, org.bukkit.plugin.ServicePriority prio) Registers a Bukkit service and tracks it for automatic unregister.- Parameters:
service
- Service interface class.provider
- Service implementation instance.prio
- Registration priority.
-
registerCloseable
Registers a closeable resource to be closed during cleanup.- Type Parameters:
T
- Resource type.- Parameters:
closeable
- Resource to track.- Returns:
- The same resource for chaining.
-
addShutdownHook
Adds a hook to be invoked during cleanup.- Parameters:
hook
- Runnable to execute on shutdown.
-
importLibrary
Imports external libraries for this module using the configured importer.- Parameters:
coordinates
- One or more coordinates (implementation-defined).
-
getGravesXModules
Exposes the per-module controller for enable/disable/isEnabled access.
-