Interface IConfigValue<T>
- Type Parameters:
T- an effectively immutable value type with stableObject.equals(Object)behavior
Keep the instance returned by IConfigValueBuilder.build(). Use get() for the setting currently in effect
and set(Object) to validate, save, and apply a new value. For settings that require a restart,
IConfigValueEditorInfo.getPendingValue() reports what is saved for the next restart while get()
continues to report the active value. Config editors can inspect saved state, identity, and metadata through
getEditorInfo().
Runtime methods and listener registration are thread-safe. Listeners run synchronously after a change is applied. Listener registrations normally live as long as this config value, which is usually the full mod lifetime, so callers may ignore their returned removal callbacks. Keep and run a removal callback when its listener captures a shorter-lived object, such as a screen, reloadable runtime, or connection-specific component. Client-per-world values retain their listeners across world changes and notify them when the effective value changes.
- Since:
- 0.1.0
-
Method Summary
Modifier and TypeMethodDescriptionObserve the complete effective-value batch whenever it includes this setting.addListener(IConfigValueChangeListener<T> listener) Run code when this setting'sget()changes.get()Get the value currently in effect.Get the saved state, identity, metadata, and listener hooks used by config editors.booleanValidate and save a new value.
-
Method Details
-
get
T get()Get the value currently in effect.Values are immutable by contract. Built-in list values return an unmodifiable snapshot.
- Since:
- 0.1.0
-
set
Validate and save a new value.The value becomes effective immediately unless this setting has a restart requirement. Use
IConfigSchema.batchUpdate(Consumer)when several settings must change together.- Parameters:
value- new value- Returns:
trueif the saved value changed, orfalseif it was valid but already pending- Throws:
IllegalArgumentException- if the value is invalid or cannot be safely serializedIllegalStateException- if this value's schema has no active local backing file, including synchronized server values viewed on a remote client- Since:
- 0.1.0
-
addListener
Run code when this setting'sget()changes.Use this to refresh behavior that depends on the active value. A restart-required edit invokes this listener only when the saved value becomes effective.
- Parameters:
listener- callback accepting the applied change- Returns:
- a callback that removes this listener
- Since:
- 0.1.0
-
addBatchListener
Observe the complete effective-value batch whenever it includes this setting.Register the same listener on every setting a reaction depends on. When several of those settings change together, the listener runs once with the complete batch.
- Parameters:
listener- callback accepting the applied changes- Returns:
- a callback that removes this listener
- Since:
- 0.1.0
-
getEditorInfo
IConfigValueEditorInfo<T> getEditorInfo()Get the saved state, identity, metadata, and listener hooks used by config editors.- Since:
- 0.3.0
-