@AutoRegister
class TestRead : DescriptionRead(ReadPriority.BEFORE, AttributeReadType.VALUE, true){
override fun read(key: String, lore: String): Array<Number> {
var array = arrayOf<Number>(0.0, 0.0)
//判断描述内是否包含括号
if (lore.contains("[()]".toRegex())){
//取出括号内的值
val value = lore.getValue("\\((.*?)\\)")
array = arrayOf(value, value)
}
return array
}
fun String.getValue(regex: String): Double {
val p: Pattern = Pattern.compile(regex)
val m: Matcher = p.matcher(this)
while (m.find()) {
return m.group(1).replace("[^0-9.-]".toRegex(), "").toDoubleOrNull() ?: 0.0
}
return 0.0
}
}
@AutoRegister
class TestRead : DescriptionRead(ReadPriority.BEFORE, AttributeReadType.BOOLEAN, true){
//使用 @AutoIncreaseKey 注释来新增标签,如果不这样做则不会读取这个标签
//当然你也可以使用 AttributeManager 内的 increaseKey(string: String) 方法来新增
@AutoIncreaseKey
val level: String = "装备等级"
override fun condition(entity: LivingEntity, lore: String): Boolean {
if (lore.contains(level) && entity is Player){
//获取描述上的装备等级要求值,这边我就从简的写了
val value = lore.split(level)[1].toIntOrNull() ?: 0
return entity.level >= value
}
return true
}
}