> For the complete documentation index, see [llms.txt](https://ersha.gitbook.io/nk-attributeplus/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ersha.gitbook.io/nk-attributeplus/zi-ding-yi-shu-xing/customattribute.md).

# CustomAttribute

自定义属性

## 构造器

| 参数名                         | 说明    |
| --------------------------- | ----- |
| AttributeType attributeType | 属性类型  |
| String attributeName        | 默认属性名 |
| String placeholder          | 属性变量名 |
| int priority                | 属性优先级 |

> &#x20;**属性类型** 请查看 属性类型 页面\
> &#x20;**默认属性名** 也就是没在 AttributePlus 内 config.yml 配置自定义属性名前的属性名 (自定义属性名看下方)\
> &#x20;**属性变量名**\
> &#x20;  — 属性注册后将自动注册一个 **%ap\_变量名%** 的 **PlaceholderAPI 变量**\
> &#x20;  — 自定义属性名的节点名是 **attribute.key.变量名** 例如物理伤害的变量是 %ap\_damage% 那么自定义属      　   性的节点名就是 **attribute.key.damage  `[注-图1]`**\
> &#x20;  — 设置属性自定义优先级同上方,但节点名为 **attribute.priority.变量名** 如果没自定义则按注册时所设\
> **属性优先级** 属性的处理顺序仅 **ATTACK DEFENSE UPDATE** 属性类型时有效 **OTHER** 类型属性默认 0

![图-1](https://3841930921-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MGpwDFnHhIuueU8Vkcp%2F-MGq8CRFaYAfuDqU3Q5L%2F-MGq8Tz5tQCgd63wuXm0%2F%E5%90%8D.png?alt=media\&token=8fc6e221-9906-4b60-9c20-d3faaf641d2b)

## 处理方法

| 方法名                                  | 说明                       |
| ------------------------------------ | ------------------------ |
| cast(Entity attacker, Entity entity) | 适合 ATTACK / DEFENSE 类型属性 |
| cast(Entity entity)                  | 适合 UPDATE 类属性            |

> 自定义属性请根据类型 **override** 以上方法

## 方法

| 方法名                             | 说明                                  |
| ------------------------------- | ----------------------------------- |
| getRandomValue()                | 获取该属性的随机值(如果为 100 则返回 **固定值(100)**) |
| addDamage(double damage)        | 增加此次事件伤害                            |
| takeDamage(double damage)       | 减少此次事件伤害                            |
| setCancelled(boolean cancelled) | 权限此次事件伤害                            |
