Class EntityAttributes

java.lang.Object
com.github.darksoulq.abyssallib.world.data.attribute.EntityAttributes

public class EntityAttributes extends Object
Manages custom attributes and modifiers for entities with persistent storage support. This class acts as a bridge between the SQLite database and dynamic AttributeInstances. Only supports attributes explicitly registered in Registries.ATTRIBUTES.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a modifier to an attribute, allowing for event-driven logic to override the application.
    void
     
    Retrieves a map containing all raw attribute keys and values for this entity.
    double
    Retrieves the raw base value of an attribute without applying any modifiers.
    Retrieves or creates the active instance for a given registered attribute.
    double
    Retrieves the final calculated value of an attribute after applying all modifiers.
    boolean
    has(Attribute attr)
    Checks if a specific attribute has been defined or loaded for this entity.
    static void
    Initializes the global attribute database and ensures the table structure exists.
    static void
    Initializes the SQLite table used for persistent attribute storage.
    void
    Asynchronously loads all attribute data for this entity from the database.
    of(UUID uuid)
    Retrieves the attribute container for a specific UUID.
    of(org.bukkit.entity.Entity entity)
    Retrieves the attribute container for a specific entity.
    void
    removeModifier(Attribute attr, net.kyori.adventure.key.Key id)
    Removes a specific modifier from an attribute based on its unique Key.
    void
    setBaseValue(Attribute attr, double value)
    Sets the base value of an attribute, triggering a change event and updating the database.
    void
     
    static void
     

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • init

      public static void init()
      Initializes the global attribute database and ensures the table structure exists.
      Throws:
      RuntimeException - If the database connection or table initialization fails.
    • of

      public static EntityAttributes of(org.bukkit.entity.Entity entity)
      Retrieves the attribute container for a specific entity.
      Parameters:
      entity - The Entity instance.
      Returns:
      The associated EntityAttributes manager.
    • of

      public static EntityAttributes of(UUID uuid)
      Retrieves the attribute container for a specific UUID.
      Parameters:
      uuid - The UUID of the target entity.
      Returns:
      The associated EntityAttributes manager.
    • getInstance

      public AttributeInstance getInstance(Attribute attr)
      Retrieves or creates the active instance for a given registered attribute.
      Parameters:
      attr - The Attribute definition.
      Returns:
      The AttributeInstance.
      Throws:
      IllegalArgumentException - If the attribute is not registered.
    • setBaseValue

      public void setBaseValue(Attribute attr, double value)
      Sets the base value of an attribute, triggering a change event and updating the database.
      Parameters:
      attr - The Attribute definition to update.
      value - The new base value to assign.
      Throws:
      IllegalArgumentException - If the attribute is not registered.
    • addModifier

      public void addModifier(Attribute attr, AttributeModifier modifier)
      Adds a modifier to an attribute, allowing for event-driven logic to override the application.
      Parameters:
      attr - The Attribute instance to modify.
      modifier - The AttributeModifier determining how the value interacts with the base.
      Throws:
      IllegalArgumentException - If the attribute is not registered.
    • removeModifier

      public void removeModifier(Attribute attr, net.kyori.adventure.key.Key id)
      Removes a specific modifier from an attribute based on its unique Key.
      Parameters:
      attr - The Attribute instance to update.
      id - The unique Key of the modifier to remove.
      Throws:
      IllegalArgumentException - If the attribute is not registered.
    • has

      public boolean has(Attribute attr)
      Checks if a specific attribute has been defined or loaded for this entity.
      Parameters:
      attr - The Attribute to check for.
      Returns:
      True if the attribute exists in the local data map or has an active instance.
      Throws:
      IllegalArgumentException - If the attribute is not registered.
    • getBaseValue

      public double getBaseValue(Attribute attr)
      Retrieves the raw base value of an attribute without applying any modifiers.
      Parameters:
      attr - The Attribute to retrieve.
      Returns:
      The deserialized base value.
      Throws:
      IllegalArgumentException - If the attribute is not registered.
    • getValue

      public double getValue(Attribute attr)
      Retrieves the final calculated value of an attribute after applying all modifiers.
      Parameters:
      attr - The Attribute to retrieve.
      Returns:
      The final calculated value.
      Throws:
      IllegalArgumentException - If the attribute is not registered.
    • getAllAttributes

      public Map<String,String> getAllAttributes()
      Retrieves a map containing all raw attribute keys and values for this entity.
      Returns:
      A Map of string-serialized attribute data.
    • load

      public void load()
      Asynchronously loads all attribute data for this entity from the database. Only loads data for attributes currently present in the registry.
    • delete

      public void delete()
    • unload

      public void unload()
    • unloadIfCached

      public static void unloadIfCached(UUID uuid)
    • initTable

      public static void initTable()
      Initializes the SQLite table used for persistent attribute storage.