Class AbstractConfig
java.lang.Object
net.joseplay.allianceutils.api.configuration.AbstractConfig
- Direct Known Subclasses:
TimeCommandsConfig
Base abstraction for configuration systems.
Handles loading, validation, caching and default value fallback.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceContract for configuration keys.static enumSupported config value types. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractConfig(File file, String configPath, Class<E> keys) Initializes configuration file and loads all values. -
Method Summary
Modifier and TypeMethodDescriptionprotected <E extends Enum<E> & AbstractConfig.ConfigKey>
voidcreateInexistentConfig(Class<E> keys) Creates missing or null config paths with default values.<P extends Enum & AbstractConfig.ConfigKey>
booleangetBoolean(P key) protected abstract AbstractConfig.ConfigKeygetConfigKey(Enum<?> key) Maps enum to ConfigKey.protected abstract ObjectgetDefaultValue(Enum<?> key) Provides default value for a key.<P extends Enum & AbstractConfig.ConfigKey>
doublegetDouble(P key) getFileInPlugin(File file) Copies default config from plugin resources if file does not exist.<P extends Enum & AbstractConfig.ConfigKey>
intgetInt(P key) <P extends Enum & AbstractConfig.ConfigKey>
List<Integer> getIntList(P key) <P extends Enum & AbstractConfig.ConfigKey>
longgetLong(P key) <P extends Enum & AbstractConfig.ConfigKey>
StringgetString(P key) <P extends Enum & AbstractConfig.ConfigKey>
List<String> getStringList(P key) <T> TRetrieves a cached value or fallback default.<P extends Enum & AbstractConfig.ConfigKey,C>
CgetValue(P key, AbstractConfig.ValueType type) Retrieves a typed value with validation.protected <E extends Enum<E> & AbstractConfig.ConfigKey>
voidinitConfig(Class<E> keys) Initializes config values and ensures missing entries are created.protected voidEnsures file structure exists.protected <E extends Enum<E> & AbstractConfig.ConfigKey>
voidloadValues(Class<E> enumClass) Loads values from config into cache.protected StringprocessMessage(String rawMsg) Applies gradient formatting to messages.voidSaves configuration to disk.booleanUpdates config value in memory and persists to file.
-
Field Details
-
file
-
configPath
-
config
protected org.bukkit.configuration.file.FileConfiguration config -
values
Cached config values mapped by enum keys.
-
-
Constructor Details
-
AbstractConfig
Initializes configuration file and loads all values.- Parameters:
file- Configuration file (e.g., config.yml)configPath- Root path inside config (can be empty)keys- Enum class implementing ConfigKey
-
-
Method Details
-
getFileInPlugin
Copies default config from plugin resources if file does not exist. -
loadConfig
protected void loadConfig()Ensures file structure exists. -
initConfig
Initializes config values and ensures missing entries are created. -
createInexistentConfig
Creates missing or null config paths with default values. -
processMessage
Applies gradient formatting to messages. -
saveConfig
Saves configuration to disk.- Throws:
IOException
-
loadValues
Loads values from config into cache. Applies validation and fallback to default values. -
getValue
Retrieves a cached value or fallback default. -
getValue
public <P extends Enum & AbstractConfig.ConfigKey,C> C getValue(P key, AbstractConfig.ValueType type) Retrieves a typed value with validation. -
getString
-
getStringList
-
getInt
-
getLong
-
getIntList
-
getBoolean
-
getDouble
-
setValue
Updates config value in memory and persists to file. -
getDefaultValue
Provides default value for a key. -
getConfigKey
Maps enum to ConfigKey.
-