Class Memory
java.lang.Object
net.citizensnpcs.api.ai.tree.expr.Memory
Persistent state storage for behavior trees. Memory allows behaviors to share data across ticks and execution cycles.
Wraps a
MetadataStore for persistence support.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all data from memory.Gets a value from memory.Gets a value with a default.booleangetBoolean(String key) Gets a boolean value.booleangetBoolean(String key, boolean defaultValue) Gets a boolean value with default.getKeys()Gets all keys in memory.Gets a list from memory, creating it if it doesn't exist.doubleGets a number value.doubleGets a number value with default.getStore()Gets the underlying MetadataStore.Gets a string value.Gets a string value with default.booleanChecks if a key exists.voidAdds an item to a list in memory.voidClears all items from a list.booleanlistContains(String key, Object item) Checks if a list contains an item.Gets an item from a list by index.booleanlistRemove(String key, Object item) Removes an item from a list by value.listRemoveAt(String key, int index) Removes an item from a list by index.voidSets an item in a list by index.intGets the size of a list.voidLoads memory state from the given DataKey.voidRemoves a value from memory.voidSaves memory state to the given DataKey.voidSets a value in memory.intsize()Gets the number of entries in memory.
-
Constructor Details
-
Memory
public Memory() -
Memory
-
-
Method Details
-
clear
public void clear()Clears all data from memory. Note: this creates a new backing store. -
get
Gets a value from memory.- Parameters:
key- the key- Returns:
- the value, or null if not found
-
get
Gets a value with a default.- Parameters:
key- the keydefaultValue- the default value if not found- Returns:
- the value or default
-
getBoolean
Gets a boolean value.- Parameters:
key- the key- Returns:
- the boolean value, or false if not found
-
getBoolean
Gets a boolean value with default.- Parameters:
key- the keydefaultValue- the default value- Returns:
- the boolean value or default
-
getKeys
Gets all keys in memory.- Returns:
- iterable of keys
-
getList
Gets a list from memory, creating it if it doesn't exist.- Parameters:
key- the key- Returns:
- the list (never null)
-
getNumber
Gets a number value.- Parameters:
key- the key- Returns:
- the number value, or 0 if not found or not a number
-
getNumber
Gets a number value with default.- Parameters:
key- the keydefaultValue- the default value- Returns:
- the number value or default
-
getStore
Gets the underlying MetadataStore.- Returns:
- the backing store
-
getString
Gets a string value.- Parameters:
key- the key- Returns:
- the string value, or null if not found
-
getString
Gets a string value with default.- Parameters:
key- the keydefaultValue- the default value- Returns:
- the string value or default
-
has
Checks if a key exists.- Parameters:
key- the key- Returns:
- true if the key exists
-
listAdd
Adds an item to a list in memory.- Parameters:
key- the list keyitem- the item to add (must be primitive)- Throws:
IllegalArgumentException- if item is not primitive
-
listClear
Clears all items from a list.- Parameters:
key- the list key
-
listContains
Checks if a list contains an item.- Parameters:
key- the list keyitem- the item- Returns:
- true if the list contains the item
-
listGet
Gets an item from a list by index.- Parameters:
key- the list keyindex- the index- Returns:
- the item, or null if index out of bounds
-
listRemove
Removes an item from a list by value.- Parameters:
key- the list keyitem- the item to remove- Returns:
- true if the item was removed
-
listRemoveAt
Removes an item from a list by index.- Parameters:
key- the list keyindex- the index- Returns:
- the removed item, or null if index out of bounds
-
listSet
Sets an item in a list by index.- Parameters:
key- the list keyindex- the indexitem- the item (must be primitive)- Throws:
IllegalArgumentException- if item is not primitive
-
listSize
Gets the size of a list.- Parameters:
key- the list key- Returns:
- the list size
-
loadFrom
Loads memory state from the given DataKey.- Parameters:
key- the key to load from
-
remove
Removes a value from memory.- Parameters:
key- the key
-
saveTo
Saves memory state to the given DataKey.- Parameters:
key- the key to save to
-
set
Sets a value in memory. Only primitive types (String, Number, Boolean, Character) and Lists of primitives are allowed. Values are stored persistently.- Parameters:
key- the keyvalue- the value (must be String, Number, Boolean, Character, List of primitives, or null)- Throws:
IllegalArgumentException- if value is not a valid type
-
size
public int size()Gets the number of entries in memory.- Returns:
- the size
-