Package dev.crafty.core.config
Class ConfigWatcher
java.lang.Object
dev.crafty.core.config.ConfigWatcher
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
ConstructorsConstructorDescriptionConfigWatcher
(org.bukkit.plugin.Plugin plugin, File configFile, Runnable onChangeCallback) Create a new config watcher. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigWatcher
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()
Start watching the configuration file for changes.void
stop()
Stop watching the configuration file for changes.
-
Constructor Details
-
ConfigWatcher
Create a new config watcher.- Parameters:
plugin
- The plugin that owns the configuration fileconfigFile
- The configuration file to watchonChangeCallback
- 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 fileonChangeCallback
- 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
-