Class ScriptStateStore

java.lang.Object
com.soulfiremc.server.script.ScriptStateStore

public final class ScriptStateStore extends Object
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 Details

    • ScriptStateStore

      public ScriptStateStore()
  • Method Details

    • getOrCreate

      public <T> T getOrCreate(String key, Supplier<T> factory)
      Gets an existing value or creates a new one using the factory.
      Type Parameters:
      T - the value type
      Parameters:
      key - the state key
      factory - supplier to create the initial value
      Returns:
      the existing or newly created value
    • getOrCreate

      public <T> T getOrCreate(String key, Class<T> type, Supplier<T> factory)
      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 key
      type - the expected type
      factory - 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.