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 provides a bridge between raw database values and functional Attribute objects, allowing for complex arithmetic modifications and event-driven updates.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends Number>
    void
    addModifier(Attribute<T> attr, net.kyori.adventure.key.Key id, T modifier, AttributeOperation operation)
    Adds a modifier to an attribute, allowing for event-driven logic to override the application.
    <T extends Number>
    T
    get(Attribute<T> attr)
    Retrieves the final calculated value of an attribute after applying all modifiers.
    Retrieves a map containing all raw attribute keys and values for this entity.
    <T extends Number>
    T
    Retrieves the raw base value of an attribute without applying any 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.
    <T extends Number>
    void
    removeModifier(Attribute<T> attr, net.kyori.adventure.key.Key id)
    Removes a specific modifier from an attribute based on its unique Key.
    <T extends Number>
    void
    set(Attribute<T> attr, T value)
    Sets the base value of an attribute, triggering a change event and updating the database.

    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.
    • set

      public <T extends Number> void set(Attribute<T> attr, T value)
      Sets the base value of an attribute, triggering a change event and updating the database.
      Type Parameters:
      T - The numeric type of the attribute.
      Parameters:
      attr - The Attribute definition to update.
      value - The new base value to assign.
    • addModifier

      public <T extends Number> void addModifier(Attribute<T> attr, net.kyori.adventure.key.Key id, T modifier, AttributeOperation operation)
      Adds a modifier to an attribute, allowing for event-driven logic to override the application.
      Type Parameters:
      T - The numeric type of the attribute and modifier.
      Parameters:
      attr - The Attribute instance to modify.
      id - The unique Key identifying this specific modifier.
      modifier - The value of the modifier.
      operation - The AttributeOperation determining how the modifier is applied.
    • removeModifier

      public <T extends Number> void removeModifier(Attribute<T> attr, net.kyori.adventure.key.Key id)
      Removes a specific modifier from an attribute based on its unique Key.
      Type Parameters:
      T - The numeric type of the attribute.
      Parameters:
      attr - The Attribute instance to update.
      id - The unique Key of the modifier to remove.
    • 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 key exists in the local data map.
    • getBaseValue

      public <T extends Number> T getBaseValue(Attribute<T> attr)
      Retrieves the raw base value of an attribute without applying any modifiers.
      Type Parameters:
      T - The numeric type of the attribute.
      Parameters:
      attr - The Attribute to retrieve.
      Returns:
      The deserialized base value, or null if not found.
    • get

      public <T extends Number> T get(Attribute<T> attr)
      Retrieves the final calculated value of an attribute after applying all modifiers.
      Type Parameters:
      T - The numeric type of the attribute.
      Parameters:
      attr - The Attribute to retrieve.
      Returns:
      The final calculated value, or null if the base value is missing.
    • 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.
    • initTable

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