Class AccidentalDamageHandler
-
- All Implemented Interfaces:
-
cn.org.bukkit.craneattribute.api.attribute.handler.AttributeHandler,cn.org.bukkit.craneattribute.api.attribute.handler.AttributeTracker,cn.org.bukkit.craneattribute.api.attribute.handler.BlockTracker,cn.org.bukkit.craneattribute.api.attribute.handler.Cancellable,cn.org.bukkit.craneattribute.api.attribute.handler.DamageTracker,cn.org.bukkit.craneattribute.api.attribute.handler.MetadataTracker
public class AccidentalDamageHandler implements AttributeHandler, DamageTracker, AttributeTracker, MetadataTracker, BlockTracker, Cancellable
-
-
Field Summary
Fields Modifier and Type Field Description private final AttributeTypetypeprivate BooleanisCancelledprivate final UUIDitprivate final LivingEntityentityprivate final Map<UUID, Map<String, Double>>damageDataprivate final Map<UUID, AttributeData>dataMapprivate final Map<UUID, Map<String, DoubleArray>>tempAttributeprivate final Map<UUID, Set<String>>triggerAttributeprivate final Map<UUID, Map<String, Object>>metadataprivate final AttributeDataentityDataprivate final EntityDamageEventeventprivate final BooleanisFromBlockprivate final Blockblock
-
Constructor Summary
Constructors Constructor Description AccidentalDamageHandler(AttributeData entityData, EntityDamageEvent event, Boolean isFromBlock, Block block)
-
Method Summary
Modifier and Type Method Description AttributeTypegetType()此处理器关联的属性类型。 BooleanisCancelled()标识当前操作是否已被取消。 当值为
true时,通常表示应跳过该操作的执行(如阻止伤害、技能释放、属性应用等);当值为
false(默认)时,表示操作正常进行。
UnitsetCancelled(Boolean isCancelled)标识当前操作是否已被取消。 当值为
true时,通常表示应跳过该操作的执行(如阻止伤害、技能释放、属性应用等);当值为
false(默认)时,表示操作正常进行。
final UUIDgetIt()final LivingEntitygetEntity()Map<UUID, Map<String, Double>>getDamageData()伤害数据存储结构。外层键:实体的唯一标识符(UUID) 内层键:伤害来源标识(如 "FIRE", "PLAYER", "GENERIC" 等自定义字符串) 值:该来源对该实体造成的累计伤害值(Double,最小为 0. Map<UUID, AttributeData>getDataMap()存储所有实体的完整属性数据映射表。 键:实体的唯一标识符(UUID) 值:该实体对应的 AttributeData 对象,包含基础值、百分比加成等结构化属性数据。 Map<UUID, Map<String, DoubleArray>>getTempAttribute()存储每个实体的临时属性值。 外层键:实体 UUID 内层键:属性名称 值:一个 DoubleArray,表示该临时属性的最小值和最大值(用于随机范围计算)。 Map<UUID, Set<String>>getTriggerAttribute()记录每个实体当前被“触发”的属性名称集合。 用于标记某些属性是否处于激活状态。 键:实体 UUID 值:被触发的属性名称集合(String 集合)。 Map<UUID, Map<String, Object>>getMetadata()元数据存储结构。外层键:实体的唯一标识符(UUID) 内层键:元数据的字符串键名(如 "last_attack_time", "immune_to_fire") 值:任意类型的对象(Any),可存储数字、字符串、布尔值、自定义对象等 final AttributeDatagetEntityData()final EntityDamageEventgetEvent()BooleanisFromBlock()标识当前上下文是否由方块触发或来源于方块。例如:被仙人掌扎或调入岩浆方块时,此值为 true。 BlockgetBlock()当前关联的方块对象(如果存在)。若 isFromBlock 为 true,则此字段通常指向触发事件的具体方块; 若为 false 或无关联方块,则为 null。 Booleanhandle()执行属性处理逻辑。子类应在此方法中: 获取目标实体(或实体对);
调用 filterAttributes 筛选有效组件;
遍历组件并调用其对应钩子方法。
final DoublegetItDamage()获取“意外伤害”的累计值。此处的 "It" 是一个抽象概念,代表无法归因于具体实体或来源的系统性伤害 (如跌落、窒息、虚空、熔岩等环境伤害),在内部使用一个预定义的 UUID(通常命名为 it) 作为其唯一标识进行存储和查询。注意:调用此方法要求实现类中存在名为 it 的 UUID 常量, 且该常量被一致地用于所有“意外伤害”的记录。 -
Methods inherited from class cn.org.bukkit.craneattribute.api.attribute.handler.AttributeHandler
filterAttributes, filterAttributes -
Methods inherited from class cn.org.bukkit.craneattribute.api.attribute.handler.DamageTracker
addDamage, addDamage, addDamage, addDamage, getDamage, getDamage, getDamage, getDamage, getDamageData, getDamageData, multiplyDamage, multiplyDamage, multiplyDamageData, setDamage, setDamage, setDamage, setDamage, takeDamage, takeDamage, takeDamage, takeDamage -
Methods inherited from class cn.org.bukkit.craneattribute.api.attribute.handler.AttributeTracker
addTempAttributeValue, addTempAttributeValue, addTempAttributeValue, addTempAttributeValue, getAttrData, getAttrData, getAttributeValue, getAttributeValue, getBasicRandomValue, getBasicRandomValue, getBasicValue, getBasicValue, getPercentRandomValue, getPercentRandomValue, getPercentValue, getPercentValue, getRandomValue, getRandomValue, getTempAttributeValue, getTempAttributeValue, getTempRandomValue, getTempRandomValue, isTrigger, isTrigger, isTrigger, isTrigger, setTempAttributeValue, setTempAttributeValue, setTempAttributeValue, setTempAttributeValue, takeTempAttributeValue, takeTempAttributeValue, takeTempAttributeValue, takeTempAttributeValue, trigger, trigger, trigger, trigger, trigger, trigger -
Methods inherited from class cn.org.bukkit.craneattribute.api.attribute.handler.MetadataTracker
getMeta, getMeta, hasMeta, hasMeta, removeMeta, removeMeta, setMeta, setMeta -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
AccidentalDamageHandler
AccidentalDamageHandler(AttributeData entityData, EntityDamageEvent event, Boolean isFromBlock, Block block)
-
-
Method Detail
-
getType
AttributeType getType()
此处理器关联的属性类型。
-
isCancelled
Boolean isCancelled()
标识当前操作是否已被取消。
当值为
true时,通常表示应跳过该操作的执行(如阻止伤害、技能释放、属性应用等);当值为
false(默认)时,表示操作正常进行。
此字段可读可写,允许监听器或处理器动态决定是否中断流程。
-
setCancelled
Unit setCancelled(Boolean isCancelled)
标识当前操作是否已被取消。
当值为
true时,通常表示应跳过该操作的执行(如阻止伤害、技能释放、属性应用等);当值为
false(默认)时,表示操作正常进行。
此字段可读可写,允许监听器或处理器动态决定是否中断流程。
-
getEntity
final LivingEntity getEntity()
-
getDamageData
Map<UUID, Map<String, Double>> getDamageData()
伤害数据存储结构。
外层键:实体的唯一标识符(UUID) 内层键:伤害来源标识(如 "FIRE", "PLAYER", "GENERIC" 等自定义字符串) 值:该来源对该实体造成的累计伤害值(Double,最小为 0.0,不会为负数)
-
getDataMap
Map<UUID, AttributeData> getDataMap()
存储所有实体的完整属性数据映射表。 键:实体的唯一标识符(UUID) 值:该实体对应的 AttributeData 对象,包含基础值、百分比加成等结构化属性数据。
-
getTempAttribute
Map<UUID, Map<String, DoubleArray>> getTempAttribute()
存储每个实体的临时属性值。 外层键:实体 UUID 内层键:属性名称 值:一个 DoubleArray,表示该临时属性的最小值和最大值(用于随机范围计算)。
-
getTriggerAttribute
Map<UUID, Set<String>> getTriggerAttribute()
记录每个实体当前被“触发”的属性名称集合。 用于标记某些属性是否处于激活状态。 键:实体 UUID 值:被触发的属性名称集合(String 集合)。
-
getMetadata
Map<UUID, Map<String, Object>> getMetadata()
元数据存储结构。
外层键:实体的唯一标识符(UUID) 内层键:元数据的字符串键名(如 "last_attack_time", "immune_to_fire") 值:任意类型的对象(Any),可存储数字、字符串、布尔值、自定义对象等
-
getEntityData
final AttributeData getEntityData()
-
getEvent
final EntityDamageEvent getEvent()
-
isFromBlock
Boolean isFromBlock()
标识当前上下文是否由方块触发或来源于方块。
例如:被仙人掌扎或调入岩浆方块时,此值为 true。
-
getBlock
Block getBlock()
当前关联的方块对象(如果存在)。
若 isFromBlock 为 true,则此字段通常指向触发事件的具体方块; 若为 false 或无关联方块,则为 null。
-
handle
Boolean handle()
执行属性处理逻辑。
子类应在此方法中:
获取目标实体(或实体对);
调用 filterAttributes 筛选有效组件;
遍历组件并调用其对应钩子方法。
- Returns:
是否未取消
-
-
-