Package net.citizensnpcs.api.expr
Class ExpressionScope
java.lang.Object
net.citizensnpcs.api.expr.ExpressionScope
A variable scope for expression evaluation with lazy binding support. Variables are only computed when accessed and
cached for the evaluation cycle.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBinds a lazily-evaluated variable.Creates a child scope that inherits from this scope.Gets a variable value, computing lazy bindings if necessary.Gets the memory instance for this scope or parent scope if not present.getNPC()Gets the NPC for this scope or parent NPC if not present.Supplier<?> getSupplier(String name) Gets the supplier for a lazy binding, if it exists.Gets all variable names currently in scope.booleanChecks if a variable exists in this scope or parent scopes.booleanisConstant(String name) Checks if a variable is a lazy binding (not eagerly evaluated).voidRemoves a variable from the scope.voidClears cached lazy values.voidSets an eager (immediate) value for a variable.voidSets the memory instance for this scope.voidSets the NPC for this scope.
-
Constructor Details
-
ExpressionScope
public ExpressionScope() -
ExpressionScope
-
-
Method Details
-
bind
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
Creates a child scope that inherits from this scope. -
get
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
Gets the memory instance for this scope or parent scope if not present. -
getNPC
Gets the NPC for this scope or parent NPC if not present. -
getSupplier
Gets the supplier for a lazy binding, if it exists.- Parameters:
name- the variable name- Returns:
- the supplier, or null if the variable is not a lazy binding
-
getVariableNames
Gets all variable names currently in scope. -
has
Checks if a variable exists in this scope or parent scopes.- Parameters:
name- the variable name
-
isConstant
Checks if a variable is a lazy binding (not eagerly evaluated).- Parameters:
name- the variable name- Returns:
- true if the variable is a lazy binding
-
remove
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
Sets an eager (immediate) value for a variable. -
setMemory
Sets the memory instance for this scope. -
setNPC
Sets the NPC for this scope.
-