Class ConditionReader
-
- All Implemented Interfaces:
-
cn.org.bukkit.craneattribute.api.lifecycle.LifecycleAware,cn.org.bukkit.craneattribute.api.read.LineReader
public abstract class ConditionReader implements LineReader
抽象条件读取器基类。
用于定义基于配置行的布尔条件判断逻辑。每个子类代表一种特定的条件类型, 通过解析 ReadableLine 并结合上下文数据,返回是否满足该条件。
-
-
Constructor Summary
Constructors Constructor Description ConditionReader()
-
Method Summary
Modifier and Type Method Description abstract StringgetKey()该条件读取器所监听的键名(key)。用于在正则模板中替换 {key}占位符,也作为条件识别标识。UnitonEnable()插件启用时回调。此方法应在主线程中调用,可安全访问 Bukkit API。 建议在此完成: 监听器注册
缓存预热
外部服务连接(如数据库)
默认配置生成
UnitonDisable()插件禁用时回调。此方法应在主线程中调用,且在 Bukkit 插件系统完全关闭前执行。 建议在此完成: 取消所有调度任务(BukkitRunnable)
关闭网络连接或文件流
保存运行时数据到磁盘
清理静态引用(防 ClassLoader 泄漏)
ConfigurationSectiongetConfigSection()获取当前条件读取器在配置文件中的对应配置节。路径格式为: read condition.$configKeyBooleancondition(ReadableLine readableLine, AttributeData data, AttributeSource attributeSource)条件判断的公共入口方法。默认直接委托给 read 方法。子类可重写以添加前置校验、日志记录或调试逻辑。 final List<String>extractValues(ReadableLine readableLine, List<String> readFormat)从配置行中提取原始数值(不使用缓存)。使用默认数值正则表达式替换 @value占位符。final List<String>extractValues(ReadableLine readableLine, List<String> readFormat, String valueRegex)从配置行中提取原始数值(不使用缓存),使用自定义数值正则。 -
-
Method Detail
-
onEnable
Unit onEnable()
插件启用时回调。
此方法应在主线程中调用,可安全访问 Bukkit API。 建议在此完成:
监听器注册
缓存预热
外部服务连接(如数据库)
默认配置生成
默认实现为空,子类按需重写。
-
onDisable
Unit onDisable()
插件禁用时回调。
此方法应在主线程中调用,且在 Bukkit 插件系统完全关闭前执行。 建议在此完成:
取消所有调度任务(BukkitRunnable)
关闭网络连接或文件流
保存运行时数据到磁盘
清理静态引用(防 ClassLoader 泄漏)
默认实现为空,子类按需重写。
-
getConfigSection
ConfigurationSection getConfigSection()
获取当前条件读取器在配置文件中的对应配置节。
路径格式为:
read condition.$configKey- Returns:
对应的 ConfigurationSection,若不存在则返回 null
-
condition
Boolean condition(ReadableLine readableLine, AttributeData data, AttributeSource attributeSource)
条件判断的公共入口方法。
默认直接委托给 read 方法。子类可重写以添加前置校验、日志记录或调试逻辑。
- Parameters:
readableLine- 待解析的原始配置行封装对象data- 当前属性上下文数据(非空)attributeSource- 触发本次条件检查的属性源- Returns:
条件是否成立
-
extractValues
final List<String> extractValues(ReadableLine readableLine, List<String> readFormat)
从配置行中提取原始数值(不使用缓存)。
使用默认数值正则表达式替换
@value占位符。- Parameters:
readableLine- 待解析的配置行readFormat- 正则模板列表,支持{key}和@value占位符- Returns:
成功匹配时返回捕获的非空值列表,否则返回 null
-
extractValues
final List<String> extractValues(ReadableLine readableLine, List<String> readFormat, String valueRegex)
从配置行中提取原始数值(不使用缓存),使用自定义数值正则。
- Parameters:
readableLine- 待解析的配置行readFormat- 正则模板列表,支持{key}和@value占位符valueRegex- 用于匹配数值部分的自定义正则表达式- Returns:
成功匹配时返回捕获的非空值列表,否则返回 null
-
-
-