Class ConfigWatcher

java.lang.Object
dev.crafty.core.config.ConfigWatcher

public class ConfigWatcher extends Object
Utility class for watching configuration files for changes. This class provides methods for setting up and managing file watchers that automatically detect changes to configuration files.
Since:
1.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConfigWatcher(org.bukkit.plugin.Plugin plugin, File configFile, Runnable onChangeCallback)
    Create a new config watcher.
  • Method Summary

    Modifier and Type
    Method
    Description
    forPluginConfig(org.bukkit.plugin.Plugin plugin, Runnable onChangeCallback)
    Create a new config watcher for the plugin's config.yml file.
    boolean
    Check if the watcher is enabled.
    boolean
    setEnabled(boolean enabled)
    Set whether the watcher is enabled.
    boolean
    Start watching the configuration file for changes.
    void
    Stop watching the configuration file for changes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConfigWatcher

      public ConfigWatcher(org.bukkit.plugin.Plugin plugin, File configFile, Runnable onChangeCallback)
      Create a new config watcher.
      Parameters:
      plugin - The plugin that owns the configuration file
      configFile - The configuration file to watch
      onChangeCallback - The callback to run when the file changes
  • Method Details

    • forPluginConfig

      public static ConfigWatcher forPluginConfig(org.bukkit.plugin.Plugin plugin, Runnable onChangeCallback)
      Create a new config watcher for the plugin's config.yml file.
      Parameters:
      plugin - The plugin that owns the configuration file
      onChangeCallback - The callback to run when the file changes
      Returns:
      A new config watcher
    • start

      public boolean start()
      Start watching the configuration file for changes. This method sets up a file watcher that monitors the file for changes and calls the callback when changes are detected.
      Returns:
      True if the watcher was started successfully, false otherwise
    • stop

      public void stop()
      Stop watching the configuration file for changes. This method cleans up resources used by the file watcher.
    • isEnabled

      public boolean isEnabled()
      Check if the watcher is enabled.
      Returns:
      True if the watcher is enabled, false otherwise
    • setEnabled

      public boolean setEnabled(boolean enabled)
      Set whether the watcher is enabled. If enabled and not already started, the watcher will be started. If disabled and currently running, the watcher will be stopped.
      Parameters:
      enabled - True to enable the watcher, false to disable
      Returns:
      True if the operation was successful, false otherwise