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

public abstract class ConfigValue<T> extends Object
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.

  • Constructor Details

    • ConfigValue

      protected ConfigValue(String category, String key, T defaultValue, String description)
  • Method Details

    • category

      public String category()
      Category, or "" for the root level.
    • key

      public String key()
    • description

      public String description()
      Human readable explanation shown in the config screen.
    • kind

      public abstract ValueKind kind()
    • get

      public T get()
    • getDefault

      public T getDefault()
    • isDefault

      public boolean isDefault()
    • set

      public void set(T value)
      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

      public void onChange(Consumer<T> listener)
      Registers a change listener; fired on the thread that performed the change.
    • check

      protected abstract T check(T value)
      Validates (and possibly normalises) a value; throws when unacceptable for code-driven sets.
    • validate

      public T validate(T value)
      Validates a candidate exactly as set(Object) would, without changing anything. Used by the config screen's live validation.
      Throws:
      IllegalArgumentException - when the value is invalid
    • serialize

      protected abstract com.google.gson.JsonElement serialize(T value)
    • deserialize

      protected abstract T deserialize(com.google.gson.JsonElement element)