Class ExpressionScope

java.lang.Object
net.citizensnpcs.api.ai.tree.expr.ExpressionScope

public class ExpressionScope extends Object
A variable scope for expression evaluation with lazy binding support. Variables are only computed when accessed and cached for the evaluation cycle.
  • Constructor Details

    • ExpressionScope

      public ExpressionScope()
    • ExpressionScope

      public ExpressionScope(ExpressionScope parent)
  • Method Details

    • bind

      public void bind(String name, Supplier<?> supplier)
      Binds a lazily-evaluated variable. The supplier is called only when the variable is first accessed, and the result is cached for the evaluation cycle.
    • createChild

      public ExpressionScope createChild()
      Creates a child scope that inherits from this scope.
    • get

      public Object get(String name)
      Gets a variable value, computing lazy bindings if necessary. Lookup order: eager values -> cached lazy values -> compute lazy -> parent scope
      Parameters:
      name - the variable name
      Returns:
      the value, or null if not found
    • getMemory

      public Memory getMemory()
      Gets the memory instance for this scope or parent scope if not present.
    • getNPC

      public NPC getNPC()
      Gets the NPC for this scope or parent NPC if not present.
    • getVariableNames

      public Iterable<String> getVariableNames()
      Gets all variable names currently in scope.
    • has

      public boolean has(String name)
      Checks if a variable exists in this scope or parent scopes.
      Parameters:
      name - the variable name
    • remove

      public void remove(String name)
      Removes a variable from the scope.
    • resetCache

      public void resetCache()
      Clears cached lazy values. Call this between evaluation cycles to allow lazy values to be recomputed with fresh data.
    • set

      public void set(String name, Object value)
      Sets an eager (immediate) value for a variable.
    • setMemory

      public void setMemory(Memory memory)
      Sets the memory instance for this scope.
    • setNPC

      public void setNPC(NPC npc)
      Sets the NPC for this scope.