插件默认属性
插件提供了一些属性,供大家使用和参考
所有属性均可更改或删除,也可在 config.yml 中关闭 create system resource file 来取消创建默认文件(libs expansions attributes 都不会创建)
默认属性
attributes\attack 下
| 属性 | 文件名 | 属性类型 | 描述 |
|---|---|---|---|
| 命中几率 | 命中几率.groovy | ATTACK_AND_DEFENSE | 攻击命中目标的概率 |
| 闪避几率 | 命中几率.groovy | DEFAULT | 每1点可抵消1点命中几率 |
| 物理攻击 | 物理攻击.groovy | ATTACK_AND_DEFENSE | 基础物理攻击力 |
| 物理护甲 | 物理攻击.groovy | DEFAULT | 基础物理防御力 |
| 物理穿透 | 物理攻击.groovy | DEFAULT | 每1点可无视1点物理护甲 |
| 暴击几率 | 物理攻击.groovy | DEFAULT | 触发暴击的概率 |
| 暴击伤害 | 物理攻击.groovy | DEFAULT | 暴击时造成的伤害倍率 |
| 暴击规避 | 物理攻击.groovy | DEFAULT | 每1点可抵消1点暴击几率 |
| 暴伤抵抗 | 物理攻击.groovy | DEFAULT | 每1点可降低1点暴击伤害倍率 |
| 吸血几率 | 物理攻击.groovy | DEFAULT | 触发生命窃取的概率 |
| 吸血倍率 | 物理攻击.groovy | DEFAULT | 生命窃取的治疗量倍率 |
| 吸血规避 | 物理攻击.groovy | DEFAULT | 每1点可抵消1点吸血几率 |
| 吸血抵抗 | 物理攻击.groovy | DEFAULT | 每1点可降低1点吸血倍率 |
| 减速几率 | 减速几率.groovy | ATTACK_AND_DEFENSE | 使目标触发减速效果的概率 |
| 减速效果 | 减速几率.groovy | DEFAULT | 减速状态下的移动速度降低幅度 |
| 减速时间 | 减速几率.groovy | DEFAULT | 减速效果的持续时间(秒) |
attributes\update 下
| 属性 | 文件名 | 属性类型 | 描述 |
|---|---|---|---|
| 默认属性 | 默认属性.groovy | UPDATE_AFTER | 实体默认拥有的基础属性集合 |
| 生命值 | 生命值.groovy | UPDATE_AFTER | 实体的最大生命值上限 |
| 移速加成 | 移速加成.groovy | UPDATE_AFTER | 对实体基础移动速度的额外加成 |
attributes\update 下
| 属性 | 文件名 | 属性类型 | 描述 |
|---|---|---|---|
| 生命恢复 | 生命恢复.groovy | RUNTIME_AFTER | 玩家每隔若干秒自动恢复的生命值量 |
attributes 下
| 属性 | 文件名 | 属性类型 | 描述 |
|---|---|---|---|
| 战斗力 | 战斗力.groovy | DEFAULT | 凭空直接提升战斗力的数值 |
| 攻击间隔 | 攻击间隔.groovy | DEFAULT | 控制武器或弓箭的攻击原版冷却时间 |
GroovyAttribute
随便打开一个文件,都可以看到它有着 ... extends GroovyAttribute 这样的内容,这是它继承了 GroovyAttribute 这个类,是位于 libs 文件夹下的一个抽象类
它额外提供了一个 GroovyAttribute(AttributeType type, AttributeName attributeName) 构造方法,方便我们配合 AttributeName 管理属性配置
截止至 2025/11/29,它的代码是这样的
Groovy
package libs
import cn.org.bukkit.craneattribute.api.attribute.AttributeType
import cn.org.bukkit.craneattribute.core.attribute.Attribute
import groovy.transform.CompileStatic
@CompileStatic
abstract class GroovyAttribute extends Attribute {
GroovyAttribute(AttributeType type, AttributeName attributeName) {
this(type, attributeName.id, attributeName.name, attributeName.priority, attributeName.power, attributeName.max)
}
GroovyAttribute(AttributeType type, String id, String name, int priority, double power, double max) {
super(type, id, name, priority, power, max)
}
GroovyAttribute(String type, String id, String name, double power, double max) {
super(type, id, name, power, max)
}
}AttributeName
随便打开一个文件,都可以看到 AttributeName.xxxx 之类的东西,AttributeName 是位于 libs 文件夹下的一个枚举类
它记录了属性的 id name priority power max,这样非常便于我们管理属性
代码示例
Groovy
package libs
import groovy.transform.CompileStatic
@CompileStatic
enum AttributeName {
HIT_CHANCE("HIT_CHANCE", "命中几率", 1, 1.0D, -1),
// 其他枚举...
final String id
final String name
final int priority
final double power
final double max
AttributeName(String id, String name, int priority, double power, double max) {
this.id = id
this.name = name
this.priority = priority
this.power = power
this.max = max
}
}实际应用
以 命中几率.groovy 为例,AttributeName.HIT_CHANCE.name 就可以调用 AttributeName 这个枚举类中的 HIT_CHANCE 的 name(id priority power max 同理)
Groovy
package attributes.attack
import cn.org.bukkit.craneattribute.core.attribute.AttributeTypes
import cn.org.bukkit.craneattribute.core.attribute.handler.AttackAndDefenseHandler
import libs.GroovyAttribute
import libs.Utils
import groovy.transform.CompileStatic
import libs.AttributeName
import org.bukkit.entity.LivingEntity
@CompileStatic
class HitChance extends GroovyAttribute {
HitChance() {
super(AttributeTypes.ATTACK_AND_DEFENSE, AttributeName.HIT_CHANCE);
this.setSkipFilter(true)
Utils.registerDefaultAttribute(AttributeName.DOGE_CHANCE)
}
@Override
boolean onAttackAndDefense(LivingEntity attacker, LivingEntity entity, AttackAndDefenseHandler handler) {
double v = handler.getRandomValue(attacker, AttributeName.HIT_CHANCE.name) - handler.getRandomValue(entity, AttributeName.DOGE_CHANCE.name)
if (!Utils.chance(v)) {
handler.trigger(entity, AttributeName.DOGE_CHANCE.name)
handler.setCancelled(true)
attacker.sendMessage("§e${entity.getName()} 闪避了你的攻击!")
return false
}
return true
}
}