Class DefaultConfigManager

java.lang.Object
tech.guilhermekaua.spigotboot.config.DefaultConfigManager
All Implemented Interfaces:
ConfigManager

public class DefaultConfigManager extends Object implements ConfigManager
Default platform-neutral implementation of ConfigManager, backed by BootPlugin.
  • Constructor Details

    • DefaultConfigManager

      public DefaultConfigManager(@NotNull @NotNull BootPlugin plugin)
      Creates a new config manager with default error handling.
      Parameters:
      plugin - the boot plugin
    • DefaultConfigManager

      public DefaultConfigManager(@NotNull @NotNull BootPlugin plugin, @Nullable @Nullable ConfigReferenceErrorHandler errorHandler)
      Creates a new config manager with optional custom error handling.
      Parameters:
      plugin - the boot plugin
      errorHandler - the optional custom error handler (null for default)
    • DefaultConfigManager

      public DefaultConfigManager(@NotNull @NotNull BootPlugin plugin, @Nullable @Nullable ConfigReferenceErrorHandler errorHandler, @NotNull @NotNull List<TypeSerializerRegistryCustomizer> serializerCustomizers)
      Creates a new config manager with optional custom error handling and serializer customizers.
      Parameters:
      plugin - the boot plugin
      errorHandler - the optional custom error handler (null for default)
      serializerCustomizers - the list of serializer registry customizers to apply (may be empty)
  • Method Details

    • getSerializerRegistry

      @NotNull public @NotNull TypeSerializerRegistry getSerializerRegistry()
      Gets the serializer registry for registering custom serializers.
      Specified by:
      getSerializerRegistry in interface ConfigManager
      Returns:
      the serializer registry
    • get

      @NotNull public <T> T get(@NotNull @NotNull Class<T> configClass)
      Description copied from interface: ConfigManager
      Gets a loaded config by class.
      Specified by:
      get in interface ConfigManager
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class
      Returns:
      the config instance
    • getRef

      @NotNull public <T> @NotNull ConfigRef<T> getRef(@NotNull @NotNull Class<T> configClass)
      Description copied from interface: ConfigManager
      Gets a live reference to a config.
      Specified by:
      getRef in interface ConfigManager
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class
      Returns:
      the config reference
    • getFolderConfig

      @NotNull public <T> @NotNull Collection<T> getFolderConfig(@NotNull @NotNull Class<T> configClass)
      Description copied from interface: ConfigManager
      Gets a folder-based config (folder-config).

      If multiple folder configs exist for this item type, throws an exception instructing to use ConfigManager.getFolderConfig(Class, String) instead.

      Specified by:
      getFolderConfig in interface ConfigManager
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class
      Returns:
      the collection of config instances
    • getFolderConfig

      @NotNull public <T> @NotNull Collection<T> getFolderConfig(@NotNull @NotNull Class<T> configClass, @NotNull @NotNull String folderConfigName)
      Description copied from interface: ConfigManager
      Gets a folder config by item type and folder config name.
      Specified by:
      getFolderConfig in interface ConfigManager
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class
      folderConfigName - the folder config name
      Returns:
      the collection of config instances
    • getFolderConfigRef

      @NotNull public <T> @NotNull FolderConfigRef<T> getFolderConfigRef(@NotNull @NotNull Class<T> configClass)
      Description copied from interface: ConfigManager
      Gets a live folder config reference with edit capabilities.

      If multiple folder configs exist for this item type, throws an exception instructing to use ConfigManager.getFolderConfigRef(Class, String) instead.

      Specified by:
      getFolderConfigRef in interface ConfigManager
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class
      Returns:
      the folder config reference
    • getFolderConfigRef

      @NotNull public <T> @NotNull FolderConfigRef<T> getFolderConfigRef(@NotNull @NotNull Class<T> configClass, @NotNull @NotNull String folderConfigName)
      Description copied from interface: ConfigManager
      Gets a live folder config reference by item type and folder config name.
      Specified by:
      getFolderConfigRef in interface ConfigManager
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class
      folderConfigName - the folder config name
      Returns:
      the folder config reference
    • registerFolderConfig

      public <T> void registerFolderConfig(@NotNull @NotNull Class<T> itemType, @NotNull @NotNull FolderConfig annotation)
      Registers a folder-based config (folder-config).

      This only registers the folder config definition. Actual loading and binding happens in initializeAll().

      Type Parameters:
      T - the item type
      Parameters:
      itemType - the item type class
      annotation - the @FolderConfig annotation
    • getFolderConfigEntry

      @Nullable public <T> @Nullable FolderConfigEntry<T> getFolderConfigEntry(@NotNull @NotNull Class<T> itemType, @NotNull @NotNull String folderConfigName)
      Gets a folder config entry by item type and name.
      Type Parameters:
      T - the item type
      Parameters:
      itemType - the item type
      folderConfigName - the folder config name
      Returns:
      the entry, or null if not found
    • getFolderConfigNames

      @NotNull public @NotNull Set<String> getFolderConfigNames(@NotNull @NotNull Class<?> itemType)
      Gets all folder config names for an item type.
      Parameters:
      itemType - the item type
      Returns:
      the set of folder config names
    • initializeAll

      public void initializeAll()
      Initializes all registered configs and folder configs in topological order.

      This method must be called after all register(Class) and registerFolderConfig(Class, FolderConfig) calls are complete. It delegates to reloadAll() after setting the initialized flag.

      Throws:
      ConfigException - if a cycle is detected in references
    • isInitialized

      public boolean isInitialized()
      Checks if initialization has been completed.
      Returns:
      true if initializeAll() has been called
    • getReferenceManager

      @NotNull public @NotNull ConfigReferenceManager getReferenceManager()
      Gets the reference manager for advanced operations.
      Returns:
      the reference manager
    • get

      @Nullable public @Nullable Object get(@NotNull @NotNull String path)
      Description copied from interface: ConfigManager
      Gets a value by path.

      Format: "configName:path.to.value" or just "path.to.value"

      Specified by:
      get in interface ConfigManager
      Parameters:
      path - the path
      Returns:
      the value, or null if not found
    • get

      @Nullable public <T> T get(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type)
      Description copied from interface: ConfigManager
      Gets a typed value by path.
      Specified by:
      get in interface ConfigManager
      Type Parameters:
      T - the type
      Parameters:
      path - the path
      type - the target type
      Returns:
      the value, or null if not found
    • getConfigName

      @NotNull public @NotNull String getConfigName(@NotNull @NotNull Class<?> configClass)
      Returns the registered config name for a @Config class.
      Parameters:
      configClass - the config class
      Returns:
      the registered config name
      Throws:
      ConfigException - if the class is not a registered config
    • deserializeAt

      @Nullable public <T> T deserializeAt(@NotNull @NotNull String path, @NotNull @NotNull Class<T> type)
      Reads the value at a path and deserializes it to the target type using the serializer registry. Unlike get(String, Class) (which uses the node's built-in scalar conversion), this supports every type with a registered TypeSerializer.
      Type Parameters:
      T - the target type parameter
      Parameters:
      path - the "configName:path" (or bare "path") location
      type - the target type
      Returns:
      the deserialized value, or null when the path is absent / null
      Throws:
      ConfigException - if no serializer is registered for the type, or on a bad bare path
    • coerceDefault

      @NotNull public <T> T coerceDefault(@NotNull @NotNull String raw, @NotNull @NotNull Class<T> type)
      Coerces a raw string into the target type using the serializer registry (used for @ConfigValue defaults).
      Type Parameters:
      T - the target type parameter
      Parameters:
      raw - the raw string
      type - the target type
      Returns:
      the coerced value
      Throws:
      ConfigException - if no serializer is registered for the type, or the value cannot be parsed
    • getString

      @NotNull public @NotNull String getString(@NotNull @NotNull String path, @NotNull @NotNull String defaultValue)
      Description copied from interface: ConfigManager
      Gets a string value with default.
      Specified by:
      getString in interface ConfigManager
      Parameters:
      path - the path
      defaultValue - the default value
      Returns:
      the value or default
    • getInt

      public int getInt(@NotNull @NotNull String path, int defaultValue)
      Description copied from interface: ConfigManager
      Gets an int value with default.
      Specified by:
      getInt in interface ConfigManager
      Parameters:
      path - the path
      defaultValue - the default value
      Returns:
      the value or default
    • getLong

      public long getLong(@NotNull @NotNull String path, long defaultValue)
      Description copied from interface: ConfigManager
      Gets a long value with default.
      Specified by:
      getLong in interface ConfigManager
      Parameters:
      path - the path
      defaultValue - the default value
      Returns:
      the value or default
    • getBoolean

      public boolean getBoolean(@NotNull @NotNull String path, boolean defaultValue)
      Description copied from interface: ConfigManager
      Gets a boolean value with default.
      Specified by:
      getBoolean in interface ConfigManager
      Parameters:
      path - the path
      defaultValue - the default value
      Returns:
      the value or default
    • getDouble

      public double getDouble(@NotNull @NotNull String path, double defaultValue)
      Description copied from interface: ConfigManager
      Gets a double value with default.
      Specified by:
      getDouble in interface ConfigManager
      Parameters:
      path - the path
      defaultValue - the default value
      Returns:
      the value or default
    • getStringList

      @NotNull public @NotNull List<String> getStringList(@NotNull @NotNull String path)
      Description copied from interface: ConfigManager
      Gets a string list.
      Specified by:
      getStringList in interface ConfigManager
      Parameters:
      path - the path
      Returns:
      the list, or empty list if not found
    • register

      public <T> void register(@NotNull @NotNull Class<T> configClass)
      Description copied from interface: ConfigManager
      Registers a config class for management.
      Specified by:
      register in interface ConfigManager
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class
    • register

      public <T> void register(@NotNull @NotNull Class<T> configClass, @NotNull @NotNull ConfigSource source)
      Description copied from interface: ConfigManager
      Registers a config class with a custom source.
      Specified by:
      register in interface ConfigManager
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class
      source - the config source
    • reload

      public void reload(@NotNull @NotNull Class<?> configClass)
      Description copied from interface: ConfigManager
      Reloads a specific config.
      Specified by:
      reload in interface ConfigManager
      Parameters:
      configClass - the config class
    • reloadFolderConfigItem

      public void reloadFolderConfigItem(@NotNull @NotNull Class<?> configClass, @NotNull @NotNull String itemId)
      Description copied from interface: ConfigManager
      Reloads a specific file in a folder config.

      If multiple folder configs exist for this item type, throws an exception instructing to use ConfigManager.reloadFolderConfigItem(Class, String, String) instead.

      Specified by:
      reloadFolderConfigItem in interface ConfigManager
      Parameters:
      configClass - the config class
      itemId - the item ID (filename without extension)
    • reloadFolderConfigItem

      public void reloadFolderConfigItem(@NotNull @NotNull Class<?> configClass, @NotNull @NotNull String folderConfigName, @NotNull @NotNull String itemId)
      Description copied from interface: ConfigManager
      Reloads a specific file in a folder config by name.
      Specified by:
      reloadFolderConfigItem in interface ConfigManager
      Parameters:
      configClass - the config class
      folderConfigName - the folder config name
      itemId - the item ID (filename without extension)
    • reloadAll

      public void reloadAll()
      Description copied from interface: ConfigManager
      Reloads all managed configs.
      Specified by:
      reloadAll in interface ConfigManager
    • save

      public void save(@NotNull @NotNull Class<?> configClass)
      Description copied from interface: ConfigManager
      Saves a config (writes current values to file).
      Specified by:
      save in interface ConfigManager
      Parameters:
      configClass - the config class
    • generateDefaults

      public void generateDefaults(@NotNull @NotNull Class<?> configClass)
      Description copied from interface: ConfigManager
      Generates a default config file with comments.
      Specified by:
      generateDefaults in interface ConfigManager
      Parameters:
      configClass - the config class
    • isRegistered

      public boolean isRegistered(@NotNull @NotNull Class<?> configClass)
      Description copied from interface: ConfigManager
      Checks if a config class is registered.
      Specified by:
      isRegistered in interface ConfigManager
      Parameters:
      configClass - the config class
      Returns:
      true if registered
    • getRegisteredConfigs

      @NotNull public @NotNull Set<Class<?>> getRegisteredConfigs()
      Description copied from interface: ConfigManager
      Gets all registered config classes.
      Specified by:
      getRegisteredConfigs in interface ConfigManager
      Returns:
      the set of registered classes
    • getConfigNode

      @Nullable public @Nullable ConfigNode getConfigNode(@NotNull @NotNull String configName)
      Gets the raw config node for a config by name.

      Used by DefaultConfigReferenceLookup.

      Parameters:
      configName - the config name
      Returns:
      the config node, or null if not found
    • getConfigNames

      @NotNull public @NotNull Set<String> getConfigNames()
      Gets all registered config names.
      Returns:
      set of config names
    • getFolderConfigEntryByName

      @Nullable public @Nullable FolderConfigEntry<?> getFolderConfigEntryByName(@NotNull @NotNull String folderConfigName)
      Gets a folder config entry by name only (without item type).

      Used by DefaultConfigReferenceLookup.

      Parameters:
      folderConfigName - the folder config name
      Returns:
      the folder config entry, or null if not found
    • getAllFolderConfigNames

      @NotNull public @NotNull Set<String> getAllFolderConfigNames()
      Gets all folder config names across all item types.
      Returns:
      set of all folder config names
    • getRegisteredFolderConfigItemTypes

      @NotNull public @NotNull Set<Class<?>> getRegisteredFolderConfigItemTypes()
      Returns the distinct item types across all registered folder configs.
      Returns:
      an unmodifiable set of folder-config item types, never null