Class DefaultConfigManager
- All Implemented Interfaces:
ConfigManager
ConfigManager, backed by BootPlugin.-
Constructor Summary
ConstructorsConstructorDescriptionDefaultConfigManager(@NotNull BootPlugin plugin) Creates a new config manager with default error handling.DefaultConfigManager(@NotNull BootPlugin plugin, @Nullable ConfigReferenceErrorHandler errorHandler) Creates a new config manager with optional custom error handling.DefaultConfigManager(@NotNull BootPlugin plugin, @Nullable ConfigReferenceErrorHandler errorHandler, @NotNull List<TypeSerializerRegistryCustomizer> serializerCustomizers) Creates a new config manager with optional custom error handling and serializer customizers. -
Method Summary
Modifier and TypeMethodDescription<T> TcoerceDefault(@NotNull String raw, @NotNull Class<T> type) Coerces a raw string into the target type using the serializer registry (used for@ConfigValuedefaults).<T> TdeserializeAt(@NotNull String path, @NotNull Class<T> type) Reads the value at a path and deserializes it to the target type using the serializer registry.voidgenerateDefaults(@NotNull Class<?> configClass) Generates a default config file with comments.<T> TGets a loaded config by class.@Nullable ObjectGets a value by path.<T> TGets a typed value by path.Gets all folder config names across all item types.booleangetBoolean(@NotNull String path, boolean defaultValue) Gets a boolean value with default.@NotNull StringgetConfigName(@NotNull Class<?> configClass) Returns the registered config name for a@Configclass.Gets all registered config names.@Nullable ConfigNodegetConfigNode(@NotNull String configName) Gets the raw config node for a config by name.doubleGets a double value with default.<T> @NotNull Collection<T>getFolderConfig(@NotNull Class<T> configClass) Gets a folder-based config (folder-config).<T> @NotNull Collection<T>getFolderConfig(@NotNull Class<T> configClass, @NotNull String folderConfigName) Gets a folder config by item type and folder config name.<T> @Nullable FolderConfigEntry<T>getFolderConfigEntry(@NotNull Class<T> itemType, @NotNull String folderConfigName) Gets a folder config entry by item type and name.@Nullable FolderConfigEntry<?>getFolderConfigEntryByName(@NotNull String folderConfigName) Gets a folder config entry by name only (without item type).getFolderConfigNames(@NotNull Class<?> itemType) Gets all folder config names for an item type.<T> @NotNull FolderConfigRef<T>getFolderConfigRef(@NotNull Class<T> configClass) Gets a live folder config reference with edit capabilities.<T> @NotNull FolderConfigRef<T>getFolderConfigRef(@NotNull Class<T> configClass, @NotNull String folderConfigName) Gets a live folder config reference by item type and folder config name.intGets an int value with default.longGets a long value with default.<T> @NotNull ConfigRef<T>Gets a live reference to a config.@NotNull ConfigReferenceManagerGets the reference manager for advanced operations.Gets all registered config classes.Returns the distinct item types across all registered folder configs.@NotNull TypeSerializerRegistryGets the serializer registry for registering custom serializers.@NotNull StringGets a string value with default.getStringList(@NotNull String path) Gets a string list.voidInitializes all registered configs and folder configs in topological order.booleanChecks if initialization has been completed.booleanisRegistered(@NotNull Class<?> configClass) Checks if a config class is registered.<T> voidRegisters a config class for management.<T> voidregister(@NotNull Class<T> configClass, @NotNull ConfigSource source) Registers a config class with a custom source.<T> voidregisterFolderConfig(@NotNull Class<T> itemType, @NotNull FolderConfig annotation) Registers a folder-based config (folder-config).voidReloads a specific config.voidReloads all managed configs.voidreloadFolderConfigItem(@NotNull Class<?> configClass, @NotNull String itemId) Reloads a specific file in a folder config.voidreloadFolderConfigItem(@NotNull Class<?> configClass, @NotNull String folderConfigName, @NotNull String itemId) Reloads a specific file in a folder config by name.voidSaves a config (writes current values to file).
-
Constructor Details
-
DefaultConfigManager
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 pluginerrorHandler- 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 pluginerrorHandler- the optional custom error handler (null for default)serializerCustomizers- the list of serializer registry customizers to apply (may be empty)
-
-
Method Details
-
getSerializerRegistry
Gets the serializer registry for registering custom serializers.- Specified by:
getSerializerRegistryin interfaceConfigManager- Returns:
- the serializer registry
-
get
Description copied from interface:ConfigManagerGets a loaded config by class.- Specified by:
getin interfaceConfigManager- Type Parameters:
T- the config type- Parameters:
configClass- the config class- Returns:
- the config instance
-
getRef
Description copied from interface:ConfigManagerGets a live reference to a config.- Specified by:
getRefin interfaceConfigManager- Type Parameters:
T- the config type- Parameters:
configClass- the config class- Returns:
- the config reference
-
getFolderConfig
Description copied from interface:ConfigManagerGets 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:
getFolderConfigin interfaceConfigManager- 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:ConfigManagerGets a folder config by item type and folder config name.- Specified by:
getFolderConfigin interfaceConfigManager- Type Parameters:
T- the config type- Parameters:
configClass- the config classfolderConfigName- 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:ConfigManagerGets 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:
getFolderConfigRefin interfaceConfigManager- 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:ConfigManagerGets a live folder config reference by item type and folder config name.- Specified by:
getFolderConfigRefin interfaceConfigManager- Type Parameters:
T- the config type- Parameters:
configClass- the config classfolderConfigName- 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 classannotation- 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 typefolderConfigName- the folder config name- Returns:
- the entry, or null if not found
-
getFolderConfigNames
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)andregisterFolderConfig(Class, FolderConfig)calls are complete. It delegates toreloadAll()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
Gets the reference manager for advanced operations.- Returns:
- the reference manager
-
get
Description copied from interface:ConfigManagerGets a value by path.Format: "configName:path.to.value" or just "path.to.value"
- Specified by:
getin interfaceConfigManager- Parameters:
path- the path- Returns:
- the value, or null if not found
-
get
Description copied from interface:ConfigManagerGets a typed value by path.- Specified by:
getin interfaceConfigManager- Type Parameters:
T- the type- Parameters:
path- the pathtype- the target type- Returns:
- the value, or null if not found
-
getConfigName
Returns the registered config name for a@Configclass.- 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. Unlikeget(String, Class)(which uses the node's built-in scalar conversion), this supports every type with a registeredTypeSerializer.- Type Parameters:
T- the target type parameter- Parameters:
path- the"configName:path"(or bare"path") locationtype- 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
Coerces a raw string into the target type using the serializer registry (used for@ConfigValuedefaults).- Type Parameters:
T- the target type parameter- Parameters:
raw- the raw stringtype- 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:ConfigManagerGets a string value with default.- Specified by:
getStringin interfaceConfigManager- Parameters:
path- the pathdefaultValue- the default value- Returns:
- the value or default
-
getInt
Description copied from interface:ConfigManagerGets an int value with default.- Specified by:
getIntin interfaceConfigManager- Parameters:
path- the pathdefaultValue- the default value- Returns:
- the value or default
-
getLong
Description copied from interface:ConfigManagerGets a long value with default.- Specified by:
getLongin interfaceConfigManager- Parameters:
path- the pathdefaultValue- the default value- Returns:
- the value or default
-
getBoolean
Description copied from interface:ConfigManagerGets a boolean value with default.- Specified by:
getBooleanin interfaceConfigManager- Parameters:
path- the pathdefaultValue- the default value- Returns:
- the value or default
-
getDouble
Description copied from interface:ConfigManagerGets a double value with default.- Specified by:
getDoublein interfaceConfigManager- Parameters:
path- the pathdefaultValue- the default value- Returns:
- the value or default
-
getStringList
Description copied from interface:ConfigManagerGets a string list.- Specified by:
getStringListin interfaceConfigManager- Parameters:
path- the path- Returns:
- the list, or empty list if not found
-
register
Description copied from interface:ConfigManagerRegisters a config class for management.- Specified by:
registerin interfaceConfigManager- 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:ConfigManagerRegisters a config class with a custom source.- Specified by:
registerin interfaceConfigManager- Type Parameters:
T- the config type- Parameters:
configClass- the config classsource- the config source
-
reload
Description copied from interface:ConfigManagerReloads a specific config.- Specified by:
reloadin interfaceConfigManager- Parameters:
configClass- the config class
-
reloadFolderConfigItem
public void reloadFolderConfigItem(@NotNull @NotNull Class<?> configClass, @NotNull @NotNull String itemId) Description copied from interface:ConfigManagerReloads 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:
reloadFolderConfigItemin interfaceConfigManager- Parameters:
configClass- the config classitemId- 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:ConfigManagerReloads a specific file in a folder config by name.- Specified by:
reloadFolderConfigItemin interfaceConfigManager- Parameters:
configClass- the config classfolderConfigName- the folder config nameitemId- the item ID (filename without extension)
-
reloadAll
public void reloadAll()Description copied from interface:ConfigManagerReloads all managed configs.- Specified by:
reloadAllin interfaceConfigManager
-
save
Description copied from interface:ConfigManagerSaves a config (writes current values to file).- Specified by:
savein interfaceConfigManager- Parameters:
configClass- the config class
-
generateDefaults
Description copied from interface:ConfigManagerGenerates a default config file with comments.- Specified by:
generateDefaultsin interfaceConfigManager- Parameters:
configClass- the config class
-
isRegistered
Description copied from interface:ConfigManagerChecks if a config class is registered.- Specified by:
isRegisteredin interfaceConfigManager- Parameters:
configClass- the config class- Returns:
- true if registered
-
getRegisteredConfigs
Description copied from interface:ConfigManagerGets all registered config classes.- Specified by:
getRegisteredConfigsin interfaceConfigManager- Returns:
- the set of registered classes
-
getConfigNode
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
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
Gets all folder config names across all item types.- Returns:
- set of all folder config names
-
getRegisteredFolderConfigItemTypes
Returns the distinct item types across all registered folder configs.- Returns:
- an unmodifiable set of folder-config item types, never null
-