Class Attribute<T extends Number>

java.lang.Object
com.github.darksoulq.abyssallib.world.data.attribute.Attribute<T>
Type Parameters:
T - The type of the attribute value (e.g. Integer, Float, Double, etc).

public final class Attribute<T extends Number> extends Object
Represents a player attribute with a specific type and default value,
  • Constructor Details

    • Attribute

      public Attribute(String key, Class<T> type, T defaultValue)
      Constructs a new attribute definition.
      Parameters:
      key - The unique key for this attribute.
      type - The type class (e.g. Integer.class).
      defaultValue - The fallback value when not set.
  • Method Details

    • key

      public String key()
      Returns the unique key used to identify this attribute.
      Returns:
      the attribute key
    • type

      public Class<T> type()
      Returns the Java class representing the type of this attribute.
      Returns:
      the type class
    • defaultValue

      public T defaultValue()
      Returns the default value of this attribute.
      Returns:
      the default value
    • addModifier

      public void addModifier(net.kyori.adventure.key.Key id, T modifier, AttributeOperation operation)
      Adds a numeric modifier to this attribute. Has no effect if the type is not a supported number type.
      Parameters:
      id - The identifier for this modifier.
      modifier - The modifier value.
      operation - The arithmetic operation to apply.
    • removeModifier

      public void removeModifier(net.kyori.adventure.key.Key id)
      Removes a modifier from this attribute using its identifier.
      Parameters:
      id - The identifier of the modifier to remove.
    • getModifiers

      public Map<net.kyori.adventure.key.Key, AttributeModifier<T>> getModifiers()
      Returns the map of identifier:attribute modifier
      Returns:
      The attribute modifier map
    • applyModifiers

      public T applyModifiers(T base)
      Applies all active modifiers to a given base value. If no modifiers exist or type is unsupported, the base is returned unmodified.
      Parameters:
      base - The base (unmodified) value of the attribute.
      Returns:
      The final modified value.