Class ScriptStateStore
java.lang.Object
com.soulfiremc.server.script.ScriptStateStore
Per-script state container with typed key access.
State is scoped to the ReactiveScriptContext and is automatically
cleaned up when the script deactivates (context is GC'd).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all state, releasing references for GC.<T> TgetOrCreate(String key, Class<T> type, Supplier<T> factory) Gets an existing value or creates a new one, with runtime type checking.<T> TgetOrCreate(String key, Supplier<T> factory) Gets an existing value or creates a new one using the factory.
-
Constructor Details
-
ScriptStateStore
public ScriptStateStore()
-
-
Method Details
-
getOrCreate
-
getOrCreate
Gets an existing value or creates a new one, with runtime type checking. Records the type on first access and warns if a different type is used later.- Type Parameters:
T- the value type- Parameters:
key- the state keytype- the expected typefactory- supplier to create the initial value- Returns:
- the existing or newly created value
- Throws:
IllegalStateException- if existing value has a different type
-
clear
public void clear()Clears all state, releasing references for GC. Called when a script is cancelled.
-