Class BaseConfig
java.lang.Object
fr.hytale.loader.config.BaseConfig
- All Implemented Interfaces:
Config
- Direct Known Subclasses:
JsonConfig, YamlConfig
Base implementation for configuration files.
Provides memory management for config data as nested Maps. This class implements the core logic for getting and setting values, handling defaults, and managing nested sections.
Concrete implementations only need to handle the actual loading and saving of data from/to their specific file format (e.g., YAML, JSON).
- Since:
- 1.0.4
- Version:
- 1.0.4
- Author:
- HytaleLoader
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classInner class for config sections backed by a Map. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefault(String path, Object value) Adds a single default value.protected voidApplies default values to the current data map.booleanChecks if the config contains a value at the specified path.Gets a value from the config.Gets a value from the config with a default fallback.booleangetBoolean(String path) Gets a boolean value from the config.booleangetBoolean(String path, boolean def) Gets a boolean value from the config with a default.doubleGets a double value from the config.doubleGets a double value from the config with a default.getFile()Gets the file associated with this config.protected ObjectgetFromDefaults(String path, Object def) Helper method to get a value from the defaults map.intGets an int value from the config.intGets an int value from the config with a default.getKeys(boolean deep) Gets a set of keys at the root of the config.getKeysFromMap(Map<String, Object> map, String prefix, boolean deep) Recursive helper to retrieve keys from a map.List<?> Gets a List from the config.List<?> Gets a List from the config with a default.getSection(String path) Gets a Configuration Section.Gets a String value from the config.Gets a String value from the config with a default.getStringList(String path) Gets a List of Strings from the config.Gets all values in the config as a Map.voidSets a value in the configuration at the specified path.voidsetDefaults(Map<String, Object> defaults) Sets the default values for the configuration.
-
Field Details
-
file
The file associated with this configuration. -
data
-
defaults
-
-
Constructor Details
-
BaseConfig
Creates a new BaseConfig instance.- Parameters:
file- the configuration file
-
-
Method Details
-
get
-
get
Gets a value from the config with a default fallback.If the value is not found in the config data, it attempts to retrieve it from the defaults.
-
getFromDefaults
-
set
-
getString
-
getString
-
getInt
-
getInt
-
getDouble
-
getDouble
Gets a double value from the config with a default.Tries to parse the value as a double if it is stored as a String.
-
getBoolean
Gets a boolean value from the config.- Specified by:
getBooleanin interfaceConfig- Parameters:
path- the path to the value- Returns:
- the boolean value, or false
-
getBoolean
Gets a boolean value from the config with a default.Tries to parse the value as a boolean if it is stored as a String.
- Specified by:
getBooleanin interfaceConfig- Parameters:
path- the path to the valuedef- the default boolean- Returns:
- the boolean value, or default
-
getList
-
getList
-
getStringList
Gets a List of Strings from the config.Converts all elements in the list to String.
- Specified by:
getStringListin interfaceConfig- Parameters:
path- the path to the value- Returns:
- a List of Strings (never null, empty if not found)
-
getSection
Gets a Configuration Section.- Specified by:
getSectionin interfaceConfig- Parameters:
path- the path to the section- Returns:
- the ConfigSection, or null if not found
-
contains
-
getKeys
-
getKeysFromMap
-
getValues
-
getFile
-
setDefaults
Sets the default values for the configuration.- Specified by:
setDefaultsin interfaceConfig- Parameters:
defaults- a Map of default values
-
addDefault
Adds a single default value.- Specified by:
addDefaultin interfaceConfig- Parameters:
path- the path for the defaultvalue- the default value
-
applyDefaults
protected void applyDefaults()Applies default values to the current data map.Only adds keys/values that are missing from the current configuration data.
-