Skip to content

ConfigSetting

MDT168 edited this page Aug 17, 2026 · 4 revisions

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.


Constructors

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 be null.

  • 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 be null.

  • 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.


Instance Methods

register()

IMPORTANT NOTE

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: NullPointerException if called before initialization.

init(ConfigManager manager)

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.

getValue()

Gets the current value.

  • Returns: The active value from the config file of type T.

  • Throws: ConfigSettingNotInitializedException if called before initialization.

setValue(T value)

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.

getDefaultValue()

Gets the raw fallback default value assigned at creation.

  • Returns: The default value.

getSerializedDefaultValue()

Gets the default value formatted into its YAML-ready form.

  • Returns: The serialized string representation of the default value, or "None" if null.

getRaw()

Gets the raw uncleaned object loaded directly from the config file.

  • Returns: The raw value object.

reloadValueFromRawValue()

Re-evaluates and updates the active value from the underlying raw config data.

getName()

Gets the display name of the setting.

  • Returns: The original name string.

getKey()

Gets the formatted YAML key name.

  • Returns: The YAML key string.

getComment()

Gets the documentation comment attached to this setting.

  • Returns: The comment string.

getType()

Gets the data type handling formatting for this setting.

  • Returns: The ConfigDataType<T> instance.

getSanitizer()

Gets the sanitizer function applied to new values.

  • Returns: The BiFunction sanitizer, or null if none was set.

getConfigType()

Gets the file target setup associated with this setting.

  • Returns: The ConfigType instance.

getFilePath()

Gets the absolute file path where this setting is saved.

  • Returns: The file path string.

  • Throws: ConfigSettingNotInitializedException if called before initialization.

getLocationString()

Gets a readable string identifying the key and file path.

  • Returns: A string in the format 'key' at 'filepath'.

validateDefaultValue(T defaultValue)

Validation hook meant to be overridden by subclasses to check if the default value meets specific requirements.

  • Parameters: defaultValue - The value to check.

modifyComment(String originalComment)

Hook to modify the comment string during initialization.

  • Parameters: originalComment - The base comment string.

  • Returns: The modified comment string.

modifyValue(T originalValue)

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.

warn(String message)

Logs a warning message containing the location context of this setting.

  • Parameters: message - The error or warning detail.

warn(Object theInvalidValue, T usedValue)

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.

warnAndUseDefault(Object theInvalidValue)

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.


Static Methods

ConfigSetting.clearRawData()

Clears all stored raw configuration data from memory.