Class MessageTemplate<T,K extends ConfigHandler>
java.lang.Object
top.magstar.framework.configs.MagstarConfig<K>
top.magstar.framework.configs.MessageTemplate<T,K>
- Type Parameters:
T- 消息键的类型,通常是枚举类型K- 配置管理类的类型。
- All Implemented Interfaces:
CommandMessageProvider
public abstract class MessageTemplate<T,K extends ConfigHandler>
extends MagstarConfig<K>
implements CommandMessageProvider
抽象消息配置模板类
提供类型安全的消息访问和管理功能,支持枚举和常量两种消息键定义方式。 完整支持 SmartString 的所有高级格式化功能,包括RGB颜色、渐变、高级标签等。 子类只需要定义消息键,即可享受完整的消息管理功能。
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class top.magstar.framework.configs.MagstarConfig
config, plugin -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncombineMessages(T... keys) 组合多个消息void确保所有默认消息存在于配置文件中getCenteredMessage(T key, int width, Object... placeholders) 获取居中显示的消息protected StringgetDefaultValue(T key) 获取消息键的默认值 子类可以重写此方法来自定义默认值获取逻辑获取消息键的类型 子类必须实现此方法来指定消息键类型getMessage(T key, Object... placeholders) 获取传统格式化字符串消息(兼容旧代码)getMessageList(T key, Object... placeholders) 获取传统字符串消息列表(兼容旧代码)getMessages(T... keys) 批量获取传统字符串消息getParsedSmartMessage(T key) 获取已解析的 SmartString(处理所有格式但不处理占位符)protected String获取消息键对应的配置路径 子类可以重写此方法来自定义路径获取逻辑getPlainMessage(T key, Object... placeholders) 获取去除格式的纯文本消息getRawSmartMessage(T key) 获取原始 SmartString(不处理占位符)getSmartMessage(T key, Object... placeholders) 获取 SmartString 消息(推荐使用)getSmartMessageList(T key, Object... placeholders) 获取 SmartString 消息列表getSmartMessages(T... keys) 批量获取消息joinMessages(String separator, T... keys) 使用分隔符连接多个消息voidsendMessage(org.bukkit.command.CommandSender receiver, T key, Object... placeholders) 发送传统字符串消息(兼容性方法)voidsendMessageList(org.bukkit.command.CommandSender receiver, T key, Object... placeholders) 发送传统字符串消息列表voidsendSmartMessage(org.bukkit.command.CommandSender receiver, T key, Object... placeholders) 发送 SmartString 消息给指定接收者(推荐使用)voidsendSmartMessageList(org.bukkit.command.CommandSender receiver, T key, Object... placeholders) 发送 SmartString 消息列表voidsetMessage(T key, String message) 设置消息voidsetMessageList(T key, List<String> messages) 设置消息列表Methods inherited from class top.magstar.framework.configs.MagstarConfig
getConfig, getMessage, getPrefix, getSmartMessage, initFile, initPlugin, reload, saveConfigMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface top.magstar.framework.CommandMessageProvider
sendCommandErrorMessage, sendMissingArgumentsMessage, sendNoPermissionMessage, sendPlayerOnlyMessage, sendTooManyArgumentsMessage
-
Constructor Details
-
MessageTemplate
-
-
Method Details
-
getKeyType
-
getPath
-
getDefaultValue
-
getSmartMessage
获取 SmartString 消息(推荐使用)- Parameters:
key- 消息键placeholders- 占位符替换 (key1, value1, key2, value2, ...)- Returns:
- SmartString 实例,支持所有高级格式
-
getSmartMessageList
获取 SmartString 消息列表- Parameters:
key- 消息键placeholders- 占位符替换- Returns:
- SmartString 列表
-
getRawSmartMessage
获取原始 SmartString(不处理占位符)- Parameters:
key- 消息键- Returns:
- 原始 SmartString
-
getParsedSmartMessage
获取已解析的 SmartString(处理所有格式但不处理占位符)- Parameters:
key- 消息键- Returns:
- 解析后的 SmartString
-
getMessage
-
getMessageList
-
sendSmartMessage
-
sendMessage
-
sendSmartMessageList
-
sendMessageList
-
getCenteredMessage
获取居中显示的消息- Parameters:
key- 消息键width- 显示宽度placeholders- 占位符- Returns:
- 居中的 SmartString
-
getPlainMessage
-
combineMessages
组合多个消息- Parameters:
keys- 消息键数组- Returns:
- 组合后的 SmartString
-
joinMessages
使用分隔符连接多个消息- Parameters:
separator- 分隔符keys- 消息键数组- Returns:
- 连接后的 SmartString
-
setMessage
-
setMessageList
-
getSmartMessages
批量获取消息 -
getMessages
-
ensureDefaults
public void ensureDefaults()确保所有默认消息存在于配置文件中
-