Class Memory

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

public class Memory extends Object
Persistent state storage for behavior trees. Memory allows behaviors to share data across ticks and execution cycles. Wraps a MetadataStore for persistence support.
  • Constructor Details

    • Memory

      public Memory()
    • Memory

      public Memory(MetadataStore store)
  • Method Details

    • clear

      public void clear()
      Clears all data from memory. Note: this creates a new backing store.
    • get

      public Object get(String key)
      Gets a value from memory.
      Parameters:
      key - the key
      Returns:
      the value, or null if not found
    • get

      public Object get(String key, Object defaultValue)
      Gets a value with a default.
      Parameters:
      key - the key
      defaultValue - the default value if not found
      Returns:
      the value or default
    • getBoolean

      public boolean getBoolean(String key)
      Gets a boolean value.
      Parameters:
      key - the key
      Returns:
      the boolean value, or false if not found
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Gets a boolean value with default.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the boolean value or default
    • getKeys

      public Iterable<String> getKeys()
      Gets all keys in memory.
      Returns:
      iterable of keys
    • getList

      public List<Object> getList(String key)
      Gets a list from memory, creating it if it doesn't exist.
      Parameters:
      key - the key
      Returns:
      the list (never null)
    • getNumber

      public double getNumber(String key)
      Gets a number value.
      Parameters:
      key - the key
      Returns:
      the number value, or 0 if not found or not a number
    • getNumber

      public double getNumber(String key, double defaultValue)
      Gets a number value with default.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the number value or default
    • getStore

      public MetadataStore getStore()
      Gets the underlying MetadataStore.
      Returns:
      the backing store
    • getString

      public String getString(String key)
      Gets a string value.
      Parameters:
      key - the key
      Returns:
      the string value, or null if not found
    • getString

      public String getString(String key, String defaultValue)
      Gets a string value with default.
      Parameters:
      key - the key
      defaultValue - the default value
      Returns:
      the string value or default
    • has

      public boolean has(String key)
      Checks if a key exists.
      Parameters:
      key - the key
      Returns:
      true if the key exists
    • listAdd

      public void listAdd(String key, Object item)
      Adds an item to a list in memory.
      Parameters:
      key - the list key
      item - the item to add (must be primitive)
      Throws:
      IllegalArgumentException - if item is not primitive
    • listClear

      public void listClear(String key)
      Clears all items from a list.
      Parameters:
      key - the list key
    • listContains

      public boolean listContains(String key, Object item)
      Checks if a list contains an item.
      Parameters:
      key - the list key
      item - the item
      Returns:
      true if the list contains the item
    • listGet

      public Object listGet(String key, int index)
      Gets an item from a list by index.
      Parameters:
      key - the list key
      index - the index
      Returns:
      the item, or null if index out of bounds
    • listRemove

      public boolean listRemove(String key, Object item)
      Removes an item from a list by value.
      Parameters:
      key - the list key
      item - the item to remove
      Returns:
      true if the item was removed
    • listRemoveAt

      public Object listRemoveAt(String key, int index)
      Removes an item from a list by index.
      Parameters:
      key - the list key
      index - the index
      Returns:
      the removed item, or null if index out of bounds
    • listSet

      public void listSet(String key, int index, Object item)
      Sets an item in a list by index.
      Parameters:
      key - the list key
      index - the index
      item - the item (must be primitive)
      Throws:
      IllegalArgumentException - if item is not primitive
    • listSize

      public int listSize(String key)
      Gets the size of a list.
      Parameters:
      key - the list key
      Returns:
      the list size
    • loadFrom

      public void loadFrom(DataKey key)
      Loads memory state from the given DataKey.
      Parameters:
      key - the key to load from
    • remove

      public void remove(String key)
      Removes a value from memory.
      Parameters:
      key - the key
    • saveTo

      public void saveTo(DataKey key)
      Saves memory state to the given DataKey.
      Parameters:
      key - the key to save to
    • set

      public void set(String key, Object value)
      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 key
      value - 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