Class ConfigurationUtils

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

public class ConfigurationUtils extends Object
Utility class for working with the configuration system. This class provides helper methods for common configuration operations.
Since:
1.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the configuration manager.
    static List<Object>
    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(Object object)
    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
    Register a custom serializer.
    static void
    reload(Object object)
    Reload configuration values for an object from disk.
    static void
    reload(Object object, org.bukkit.plugin.Plugin plugin)
    Reload configuration values for an object from disk using a specific plugin's data folder.
    static int
    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.

    Methods inherited from class java.lang.Object

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

    • ConfigurationUtils

      public ConfigurationUtils()
  • Method Details

    • initialize

      public static void initialize(org.bukkit.plugin.Plugin plugin, Runnable callback)
      Initialize the configuration system. This method should be called when the plugin is enabled.
      Parameters:
      plugin - The plugin instance
    • load

      public static void load(Object object)
      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

      public 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. 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
      plugin - The plugin to load the configuration from
      Throws:
      IllegalArgumentException - If the object's class is not annotated with @ConfigurationFile
    • reload

      public static void reload(Object object)
      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

      public static void reload(Object object, org.bukkit.plugin.Plugin plugin)
      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 for
      plugin - 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

      public static int reloadAllConfigs(String pluginName)
      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

      public static <T> void registerSerializer(ConfigSerializer<T> serializer)
      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

      public static ConfigurationManager getConfigManager()
      Get the configuration manager.
      Returns:
      The configuration manager
      Throws:
      IllegalStateException - If the configuration system is not initialized
    • getRegisteredConfigs

      public static List<Object> getRegisteredConfigs(org.bukkit.plugin.Plugin plugin)
      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