Class EntityAttributes
java.lang.Object
com.github.darksoulq.abyssallib.world.data.attribute.EntityAttributes
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 TypeMethodDescriptionvoidaddModifier(Attribute attr, AttributeModifier modifier) Adds a modifier to an attribute, allowing for event-driven logic to override the application.voiddelete()Retrieves a map containing all raw attribute keys and values for this entity.doublegetBaseValue(Attribute attr) Retrieves the raw base value of an attribute without applying any modifiers.getInstance(Attribute attr) Retrieves or creates the active instance for a given registered attribute.doubleRetrieves the final calculated value of an attribute after applying all modifiers.booleanChecks if a specific attribute has been defined or loaded for this entity.static voidinit()Initializes the global attribute database and ensures the table structure exists.static voidInitializes the SQLite table used for persistent attribute storage.voidload()Asynchronously loads all attribute data for this entity from the database.static EntityAttributesRetrieves the attribute container for a specific UUID.static EntityAttributesof(org.bukkit.entity.Entity entity) Retrieves the attribute container for a specific entity.voidremoveModifier(Attribute attr, net.kyori.adventure.key.Key id) Removes a specific modifier from an attribute based on its unique Key.voidsetBaseValue(Attribute attr, double value) Sets the base value of an attribute, triggering a change event and updating the database.voidunload()static voidunloadIfCached(UUID uuid)
-
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
Retrieves the attribute container for a specific entity.- Parameters:
entity- TheEntityinstance.- Returns:
- The associated
EntityAttributesmanager.
-
of
Retrieves the attribute container for a specific UUID.- Parameters:
uuid- TheUUIDof the target entity.- Returns:
- The associated
EntityAttributesmanager.
-
getInstance
Retrieves or creates the active instance for a given registered attribute.- Parameters:
attr- TheAttributedefinition.- Returns:
- The
AttributeInstance. - Throws:
IllegalArgumentException- If the attribute is not registered.
-
setBaseValue
Sets the base value of an attribute, triggering a change event and updating the database.- Parameters:
attr- TheAttributedefinition to update.value- The new base value to assign.- Throws:
IllegalArgumentException- If the attribute is not registered.
-
addModifier
Adds a modifier to an attribute, allowing for event-driven logic to override the application.- Parameters:
attr- TheAttributeinstance to modify.modifier- TheAttributeModifierdetermining how the value interacts with the base.- Throws:
IllegalArgumentException- If the attribute is not registered.
-
removeModifier
Removes a specific modifier from an attribute based on its unique Key.- Parameters:
attr- TheAttributeinstance to update.id- The uniqueKeyof the modifier to remove.- Throws:
IllegalArgumentException- If the attribute is not registered.
-
has
Checks if a specific attribute has been defined or loaded for this entity.- Parameters:
attr- TheAttributeto 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
Retrieves the raw base value of an attribute without applying any modifiers.- Parameters:
attr- TheAttributeto retrieve.- Returns:
- The deserialized base value.
- Throws:
IllegalArgumentException- If the attribute is not registered.
-
getValue
Retrieves the final calculated value of an attribute after applying all modifiers.- Parameters:
attr- TheAttributeto retrieve.- Returns:
- The final calculated value.
- Throws:
IllegalArgumentException- If the attribute is not registered.
-
getAllAttributes
-
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
-
initTable
public static void initTable()Initializes the SQLite table used for persistent attribute storage.
-