-
Notifications
You must be signed in to change notification settings - Fork 0
ConfigSetting
The ConfigSetting<T> class represents an individual configuration entry. It links a configuration key to its data type, default value, validation rules, and file location.
This is the actual config entry that is found in the file.
ConfigSetting(String name, String comment, ConfigDataType<T> type, T defaultValue, ConfigType configType)
Creates a new configuration setting without a custom sanitizer function.
-
name: The display name of the setting. Automatically converted into a YAML key format. -
comment: Description text explaining what the setting is for. -
type: The ConfigDataType` handling serialization and deserialization (e.g., Integer Data Type, Boolean). -
defaultValue: The default fallback value if the config value was missing or invalid. Cannot benull. -
configType: The target file setup where this setting belongs.
ConfigSetting(String name, String comment, ConfigDataType<T> type, T defaultValue, ConfigType configType, BiFunction<T, ConfigSetting<T>, T> sanitizer)
Creates a new configuration setting with a custom sanitizer to clean or adjust loaded values.
-
name: The display name of the setting. Automatically converted into a YAML key format. -
comment: Description text explaining what the setting does. -
type: The ConfigDataType handling serialization and deserialization (e.g., Integer, Double, Boolean). -
defaultValue: The default fallback value. Cannot benull. -
configType: The target file setup where this setting belongs. -
sanitizer: A function applied after deserialization to clean up or modify the value before storing it.
Using register() will throw NullPointerException if init(ConfigManager manager) was not called.
This method is mostly used if the config setting was unregistered through the ConfigManager#unregister(T setting) and wanted to be registered back.
So, init() must be called
Registers this setting using its associated manager instance.
- Returns: The registered setting instance.
-
Throws:
NullPointerExceptionif called before initialization.
Initializes the setting with a manager, resolves its target file path, validates the default value, and loads its active value.
-
Parameters:
manager- The configuration manager handling this setting.
Gets the current value.
-
Returns: The active value from the config file of type
T. -
Throws:
ConfigSettingNotInitializedExceptionif called before initialization.
Updates the active value manually. Runs the sanitizer and modifier before saving the new value and updating its raw serialized state that will be saved in the file.
-
Parameters:
value- The new value to assign.
Gets the raw fallback default value assigned at creation.
- Returns: The default value.
Gets the default value formatted into its YAML-ready form.
-
Returns: The serialized string representation of the default value, or
"None"if null.
Gets the raw uncleaned object loaded directly from the config file.
- Returns: The raw value object.
Re-evaluates and updates the active value from the underlying raw config data.
Gets the display name of the setting.
- Returns: The original name string.
Gets the formatted YAML key name.
- Returns: The YAML key string.
Gets the documentation comment attached to this setting.
- Returns: The comment string.
Gets the data type handling formatting for this setting.
-
Returns: The
ConfigDataType<T>instance.
Gets the sanitizer function applied to new values.
-
Returns: The
BiFunctionsanitizer, ornullif none was set.
Gets the file target setup associated with this setting.
-
Returns: The
ConfigTypeinstance.
Gets the absolute file path where this setting is saved.
-
Returns: The file path string.
-
Throws:
ConfigSettingNotInitializedExceptionif called before initialization.
Gets a readable string identifying the key and file path.
-
Returns: A string in the format
'key' at 'filepath'.
Validation hook meant to be overridden by subclasses to check if the default value meets specific requirements.
-
Parameters:
defaultValue- The value to check.
Hook to modify the comment string during initialization.
-
Parameters:
originalComment- The base comment string. -
Returns: The modified comment string.
Hook to run class-specific modifications on a loaded value after it passes through the sanitizer.
-
Parameters:
originalValue- The value after sanitization. -
Returns: The final processed value.
Logs a warning message containing the location context of this setting.
-
Parameters:
message- The error or warning detail.
Logs a warning about an invalid value and shows which fallback value is used instead.
-
Parameters:
theInvalidValue- The invalid input value. -
Parameters:
usedValue- The replacement value used.
Logs a warning for an invalid input value and returns the setting default value.
-
Parameters:
theInvalidValue- The bad value encountered. -
Returns: The default value
defaultValue.
Clears all stored raw configuration data from memory.