Class ConfigValue<T>
java.lang.Object
my.celium.org.config.ConfigValue<T>
- Type Parameters:
T- value type
- Direct Known Subclasses:
ConfigValue.BooleanValue, ConfigValue.DoubleValue, ConfigValue.EnumValue, ConfigValue.IntegerValue, ConfigValue.LongValue, ConfigValue.StringListValue, ConfigValue.StringValue
A single typed configuration value.
Values are created through ConfigBuilder and owned by a
MycelConfig. Reads are cheap and thread-safe. Writes validate,
notify listeners and persist (debounced by the owning config).
Programmatic set(Object) calls with invalid data throw
IllegalArgumentException; data loaded from disk is clamped or
reset to the default with a warning instead, so a hand-edited file can
never crash the game.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBoolean value.static final classDouble value with an inclusive range.static final classConfigValue.EnumValue<E extends Enum<E>>Enum value; unknown names on disk fall back to the default.static final classInteger value with an inclusive range.static final classLong value with an inclusive range.static final classList-of-strings value (defensive copies in and out).static final classString value with a maximum length. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConfigValue(String category, String key, T defaultValue, String description) -
Method Summary
Modifier and TypeMethodDescriptioncategory()Category, or""for the root level.protected abstract TValidates (and possibly normalises) a value; throws when unacceptable for code-driven sets.Human readable explanation shown in the config screen.protected abstract Tdeserialize(com.google.gson.JsonElement element) get()booleankey()abstract ValueKindkind()voidRegisters a change listener; fired on the thread that performed the change.voidreset()Resets to the default value (persists + notifies when changed).protected abstract com.google.gson.JsonElementvoidSets a new value after validation.Validates a candidate exactly asset(Object)would, without changing anything.
-
Constructor Details
-
ConfigValue
-
-
Method Details
-
category
Category, or""for the root level. -
key
-
description
Human readable explanation shown in the config screen. -
kind
-
get
-
getDefault
-
isDefault
public boolean isDefault() -
set
Sets a new value after validation. Persists and notifies listeners when the value actually changed.- Throws:
IllegalArgumentException- when the value is invalid
-
reset
public void reset()Resets to the default value (persists + notifies when changed). -
onChange
-
check
-
validate
Validates a candidate exactly asset(Object)would, without changing anything. Used by the config screen's live validation.- Throws:
IllegalArgumentException- when the value is invalid
-
serialize
-
deserialize
-