Package dev.crafty.core.config
Class ConfigurationUtils
java.lang.Object
dev.crafty.core.config.ConfigurationUtils
Utility class for working with the configuration system.
This class provides helper methods for common configuration operations.
- Since:
- 1.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigurationManager
Get the configuration manager.getRegisteredConfigs
(org.bukkit.plugin.Plugin plugin) Get all registered configuration objects for a plugin.static void
initialize
(org.bukkit.plugin.Plugin plugin, Runnable callback) Initialize the configuration system.static boolean
Check if the configuration system is initialized.static void
Load configuration values into an object.static void
registerAndLoad
(Object object, org.bukkit.plugin.Plugin plugin) Register and load configuration values into an object using a specific plugin's data folder.static <T> void
registerSerializer
(ConfigSerializer<T> serializer) Register a custom serializer.static void
Reload configuration values for an object from disk.static void
Reload configuration values for an object from disk using a specific plugin's data folder.static int
reloadAllConfigs
(String pluginName) Reload all registered configuration objects for a plugin by name.static int
reloadAllConfigs
(org.bukkit.plugin.Plugin plugin) Reload all registered configuration objects for a specific plugin.static int
scanAndLoadConfigs
(org.bukkit.plugin.Plugin plugin) Scan a plugin for classes with the @ConfigurationFile annotation and automatically register and load them.
-
Constructor Details
-
ConfigurationUtils
public ConfigurationUtils()
-
-
Method Details
-
initialize
Initialize the configuration system. This method should be called when the plugin is enabled.- Parameters:
plugin
- The plugin instance
-
load
Load configuration values into an object. The object's class must be annotated with @ConfigurationFile, and its fields must be annotated with @ConfigValue.- Parameters:
object
- The object to load configuration values into- Throws:
IllegalArgumentException
- If the object's class is not annotated with @ConfigurationFile
-
registerAndLoad
Register and load configuration values into an object using a specific plugin's data folder. The object's class must be annotated with @ConfigurationFile, and its fields must be annotated with @ConfigValue.- Parameters:
object
- The object to load configuration values intoplugin
- The plugin to load the configuration from- Throws:
IllegalArgumentException
- If the object's class is not annotated with @ConfigurationFile
-
reload
Reload configuration values for an object from disk. This is useful when the configuration file has been modified externally and you want to update the object's fields with the new values. The object's class must be annotated with @ConfigurationFile, and its fields must be annotated with @ConfigValue.- Parameters:
object
- The object to reload configuration values for- Throws:
IllegalArgumentException
- If the object's class is not annotated with @ConfigurationFile
-
reload
Reload configuration values for an object from disk using a specific plugin's data folder. This is useful when the configuration file has been modified externally and you want to update the object's fields with the new values. The object's class must be annotated with @ConfigurationFile, and its fields must be annotated with @ConfigValue.- Parameters:
object
- The object to reload configuration values forplugin
- The plugin to reload the configuration from- Throws:
IllegalArgumentException
- If the object's class is not annotated with @ConfigurationFile
-
reloadAllConfigs
public static int reloadAllConfigs(org.bukkit.plugin.Plugin plugin) Reload all registered configuration objects for a specific plugin. This method will find all configuration objects registered for the plugin and reload their values from the configuration files.- Parameters:
plugin
- The plugin to reload configurations for- Returns:
- The number of configuration objects reloaded
-
reloadAllConfigs
Reload all registered configuration objects for a plugin by name. This method will find the plugin by name and reload all its registered configurations.- Parameters:
pluginName
- The name of the plugin to reload configurations for- Returns:
- The number of configuration objects reloaded, or -1 if the plugin was not found
-
registerSerializer
Register a custom serializer.- Type Parameters:
T
- The type of object the serializer handles- Parameters:
serializer
- The serializer to register
-
isInitialized
public static boolean isInitialized()Check if the configuration system is initialized.- Returns:
- True if the configuration system is initialized, false otherwise
-
getConfigManager
Get the configuration manager.- Returns:
- The configuration manager
- Throws:
IllegalStateException
- If the configuration system is not initialized
-
getRegisteredConfigs
Get all registered configuration objects for a plugin.- Parameters:
plugin
- The plugin to get configurations for- Returns:
- A list of registered configuration objects for the plugin
-
scanAndLoadConfigs
public static int scanAndLoadConfigs(org.bukkit.plugin.Plugin plugin) Scan a plugin for classes with the @ConfigurationFile annotation and automatically register and load them. This method uses reflection to find and instantiate configuration classes.- Parameters:
plugin
- The plugin to scan for configuration classes- Returns:
- The number of configuration classes found and registered
-