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

public class ConfigManager<T extends ConfigData> extends Object
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 Details

    • ConfigManager

      public ConfigManager(Path configPath, T defaultConfig, Class<T> configClass)
      Constructs a new ConfigManager with the specified parameters.
      Parameters:
      configPath - the path to the configuration file
      defaultConfig - the default configuration instance
      configClass - 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

      public T getConfig()
      Returns the current configuration instance.
      Returns:
      the current configuration instance
    • updateConfig

      public void updateConfig(T newConfig)
      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.