Skip to content

AttributeSource

属性源,所有属性值都位于属性源中,就像一个箱子一样

预设属性源

插件中默认拥有这些属性源

非静态属性源
EquipmentAttributeSource: 解析装备格子上的物品的 Lore 和 NBT 中的属性
ItemStackAttributeSource: 解析物品的 Lore 和 NBT 中的属性
ListAttributeSource: 解析 List<String> 中的属性,等同于 Lore 或 NBT

静态属性源
StaticItemStackAttributeSource: 解析物品的 Lore 和 NBT 中的属性,不再判断条件
StaticListAttributeSource: 解析 List<String> 中的属性,不再判断条件
FormatListAttributeSource: 必须按照 属性名:属性值属性名:最小值-最大值 (注意是英文符号 :)的格式解析 List<String> 中的属性,不再判断条件

Map属性源
ArrayMapAttributeSource: 解析 Map<String, DoubleArray> 中的属性,无条件判断
MapAttributeSource: 解析 Map<String, Double> 中的属性,无条件判断

编写属性源类

需要实现 cn.org.bukkit.craneattribute.api.attribute.source.PersistentAttributeSource 接口或 cn.org.bukkit.craneattribute.api.attribute.source.AttributeSource 接口

Kotlin
class ArrayMapAttributeSource(
    override var name: String,
    val valueMap: Map<String, DoubleArray>,
    val percentMap: Map<String, DoubleArray>,
    override var time: Long,
) : PersistentAttributeSource {

    override var shouldPersist: Boolean = false

    override var shouldRemoveOnUpdate: Boolean = false

    override var condition: Boolean = true

    override var values: Map<String, DoubleArray> =
        valueMap.filterKeys { AttributeManager.getAttributeNameKeys().contains(it) }

    override var percents: Map<String, DoubleArray> =
        percentMap.filterKeys { AttributeManager.getAttributeNameKeys().contains(it) }

}