Class ConfigManager<T extends ConfigData>
java.lang.Object
io.github.zhengzhengyiyi.api.config.ConfigManager<T>
- Type Parameters:
T- the type of configuration data, must extend ConfigData
Configuration manager that handles loading, saving, and monitoring configuration files.
Provides methods for accessing configuration data and automatically reloads
configuration when the file is modified externally.
-
Constructor Summary
ConstructorsConstructorDescriptionConfigManager(Path configPath, T defaultConfig, Class<T> configClass) Constructs a new ConfigManager with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionReturns the current configuration instance.booleanChecks if the file watcher is running.voidload()Loads configuration from file.voidRestarts the file watcher.voidsave()Saves current configuration to file.voidshutdown()Shuts down the file watcher thread.voidupdateConfig(T newConfig) Updates the configuration with new values and saves to file.
-
Constructor Details
-
ConfigManager
Constructs a new ConfigManager with the specified parameters.- Parameters:
configPath- the path to the configuration filedefaultConfig- the default configuration instanceconfigClass- the class object of the configuration type
-
-
Method Details
-
load
public void load()Loads configuration from file. Creates default configuration if file doesn't exist. -
save
public void save()Saves current configuration to file. -
getConfig
Returns the current configuration instance.- Returns:
- the current configuration instance
-
updateConfig
Updates the configuration with new values and saves to file.- Parameters:
newConfig- the new configuration instance
-
isWatcherRunning
public boolean isWatcherRunning()Checks if the file watcher is running.- Returns:
- true if the file watcher is running
-
restartFileWatcher
public void restartFileWatcher()Restarts the file watcher. -
shutdown
public void shutdown()Shuts down the file watcher thread. Should be called when the application exits.
-