From f41da56c62c9df7e248135373d3834f68a8c249c Mon Sep 17 00:00:00 2001 From: 502647092 Date: Fri, 9 Sep 2016 17:24:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E6=A0=BC=E5=BC=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- src/main/java/pw/yumc/MiaoChat/MiaoChat.java | 19 +++-- .../pw/yumc/MiaoChat/config/ChatConfig.java | 5 +- .../pw/yumc/MiaoChat/config/ChatRule.java | 51 +++++++++++++ .../java/pw/yumc/MiaoChat/config/Config.java | 37 ++++++++++ .../yumc/MiaoChat/listeners/ChatListener.java | 7 +- src/main/resources/config.yml | 71 +++++++------------ src/main/resources/default.yml | 54 ++++++++++++++ src/main/resources/plugin.yml | 4 +- 8 files changed, 185 insertions(+), 63 deletions(-) create mode 100644 src/main/java/pw/yumc/MiaoChat/config/ChatRule.java create mode 100644 src/main/java/pw/yumc/MiaoChat/config/Config.java create mode 100644 src/main/resources/default.yml diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java index 2f6496c..f1362d9 100644 --- a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java +++ b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java @@ -3,7 +3,7 @@ package pw.yumc.MiaoChat; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; -import pw.yumc.MiaoChat.config.ChatConfig; +import pw.yumc.MiaoChat.config.Config; import pw.yumc.MiaoChat.listeners.ChatListener; import pw.yumc.YumCore.commands.CommandArgument; import pw.yumc.YumCore.commands.CommandExecutor; @@ -13,15 +13,15 @@ import pw.yumc.YumCore.commands.annotation.Help; import pw.yumc.YumCore.config.FileConfig; public class MiaoChat extends JavaPlugin implements CommandExecutor { - private ChatConfig chatConfig; - private FileConfig config; - - public ChatConfig getChatConfig() { - return chatConfig; - } + private FileConfig cfg; + private Config config; @Override public FileConfiguration getConfig() { + return cfg; + } + + public Config getConfigExt() { return config; } @@ -33,15 +33,14 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor { @Override public void onLoad() { - config = new FileConfig(); - chatConfig = new ChatConfig(); + cfg = new FileConfig(); } @Cmd(permission = "MiaoChat.reload") @Help("重载配置文件") public void reload(final CommandArgument e) { + cfg.reload(); config.reload(); - chatConfig.reload(); e.getSender().sendMessage("§a配置文件已重载!"); } } diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java index 65fc473..0b9e610 100644 --- a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java @@ -3,7 +3,6 @@ package pw.yumc.MiaoChat.config; import java.util.LinkedList; import java.util.List; -import pw.yumc.YumCore.bukkit.P; import pw.yumc.YumCore.config.FileConfig; public class ChatConfig { @@ -14,8 +13,8 @@ public class ChatConfig { private final List suffixs; private ChatMessagePart player; - public ChatConfig() { - config = P.getConfig(); + public ChatConfig(final FileConfig cfg) { + config = cfg; prefixs = new LinkedList<>(); suffixs = new LinkedList<>(); reload(); diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java new file mode 100644 index 0000000..0b53fa5 --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatRule.java @@ -0,0 +1,51 @@ +package pw.yumc.MiaoChat.config; + +import org.bukkit.configuration.ConfigurationSection; + +import pw.yumc.YumCore.config.InjectConfigurationSection; + +/** + * 聊天规则 + * + * @since 2016年9月9日 下午4:59:47 + * @author 喵♂呜 + */ +public class ChatRule extends InjectConfigurationSection { + private Integer index; + private String permission; + private Integer range; + private boolean item; + + public ChatRule(final ConfigurationSection config) { + super(config); + } + + /** + * @return the index + */ + public Integer getIndex() { + return index; + } + + /** + * @return the permission + */ + public String getPermission() { + return permission; + } + + /** + * @return the range + */ + public Integer getRange() { + return range; + } + + /** + * @return the item + */ + public boolean isItem() { + return item; + } + +} diff --git a/src/main/java/pw/yumc/MiaoChat/config/Config.java b/src/main/java/pw/yumc/MiaoChat/config/Config.java new file mode 100644 index 0000000..9b41879 --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/config/Config.java @@ -0,0 +1,37 @@ +package pw.yumc.MiaoChat.config; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.entity.Player; + +import cn.citycraft.PluginHelper.config.FileConfig; +import pw.yumc.YumCore.bukkit.P; + +/** + * + * @since 2016年9月9日 下午4:40:50 + * @author 喵♂呜 + */ +public class Config { + FileConfig config = P.getConfig(); + Map formats = new HashMap<>(); + + public Config() { + reload(); + } + + /** + * 获得玩家可用的消息处理 + * + * @param player + * @return {@link ChatConfig} + */ + public ChatConfig getChatConfig(final Player player) { + return null; + } + + public void reload() { + + } +} diff --git a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java index 573c11b..cb5bf87 100644 --- a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java +++ b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java @@ -26,9 +26,12 @@ public class ChatListener implements Listener { @EventHandler public void onChat(final AsyncPlayerChatEvent e) { - e.setCancelled(true); final Player p = e.getPlayer(); - final ChatConfig cc = plugin.getChatConfig(); + final ChatConfig cc = plugin.getConfigExt().getChatConfig(e.getPlayer()); + if (cc == null) { + return; + } + e.setCancelled(true); final String msg = e.getMessage(); final Tellraw tr = Tellraw.create(); for (final ChatMessagePart cmp : cc.getPrefixs()) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 06111bb..d7d5e8d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,46 +1,25 @@ -#格式化配置 -Format: - #前缀配置 于玩家名称前 - Prefix: - #顺序 - 1: - #文本 支持PAPI变量 - text: '&6[&a%player_world%&6]' - #悬浮提示 支持PAPI - tip: - - '&6当前所在位置:' - - '&6世界: &d%player_world%' - - '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%' - - '' - - '&c点击即可TP我!' - #点击操作 - click: - #操作类型: [COMMAND,SUGGEST] - #COMMAND代表执行命令 - #SUGGEST代表命令补全 - type: 'COMMAND' - #命令 支持PAPI - command: '/tpa %player_name%' - #玩家名称配置 - Player: - text: '&6[&b%player_name%&6] ' - tip: - - '&6玩家名称: &b%player_name%' - - '&6玩家等级: &a%player_level%' - - '&6玩家血量: &c%player_health%' - - '&6玩家饥饿: &d%player_food_level%' - - '&6游戏模式: &4%player_gamemode%' - - '' - - '&c点击与我聊天' - click: - type: 'SUGGEST' - command: '/tell %player_name%' -#后缀配置 于玩家名称后 由于一般没人用 我注释掉了 -# Suffix: -# 1: -# text: '[变量1]' -# tip: -# - '变量1提示' -# click: -# type: 'COMMAND' -# command: 'say 命令执行' \ No newline at end of file +#配置文件版本号 请勿修改 +Version: 1.0 + +#格式列表 +Formats: + #格式名称 对应当前文件夹下的default.yml + default: + #优先级(将按照从小到大依次检测 比如 1-50 优先检测 1 符合则显示 不符合 检测 2 ...) + index: 50 + #权限 + permission: 'MiaoChat.default' + #范围(0为无限制) + range: 0 + #解析物品(%i%=>手上物品,%0-9%快捷栏对应物品) + item: true + #格式名称 对应当前文件夹下的admin.yml + admin: + #优先级(将按照从小到大依次检测 比如 1-50 优先检测 1 符合则显示 不符合 检测 2 ...) + index: 49 + #权限 + permission: 'MiaoChat.reload' + #范围(0为无限制) + range: 0 + #解析物品(%i%=>手上物品,%0-9%快捷栏对应物品) + item: true \ No newline at end of file diff --git a/src/main/resources/default.yml b/src/main/resources/default.yml new file mode 100644 index 0000000..c1133ef --- /dev/null +++ b/src/main/resources/default.yml @@ -0,0 +1,54 @@ +#格式化配置 +Format: + #前缀配置 于玩家名称前 + Prefix: + #顺序 + 1: + #文本 支持PAPI变量 + text: '&6[&a%player_world%&6]' + #悬浮提示 支持PAPI + tip: + - '&6当前所在位置:' + - '&6世界: &d%player_world%' + - '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%' + - '' + - '&c点击即可TP我!' + #点击操作 + click: + #操作类型: [COMMAND,SUGGEST] + #COMMAND代表执行命令 + #SUGGEST代表命令补全 + type: 'COMMAND' + #命令 支持PAPI + command: '/tpa %player_name%' +# 可以添加多个 +# 2: +# #文本 支持PAPI变量 +# text: '&6[&a%player_world%&6]' +# #悬浮提示 支持PAPI +# tip: [] + #玩家名称配置 + Player: + text: '&b%player_name% ' + tip: + - '&6玩家名称: &b%player_name%' + - '&6玩家等级: &a%player_level%' + - '&6玩家血量: &c%player_health%' + - '&6玩家饥饿: &d%player_food_level%' + - '&6游戏模式: &4%player_gamemode%' + - '' + - '&c点击与我聊天' + click: + type: 'SUGGEST' + command: '/tell %player_name%' +#后缀配置 于玩家名称后 由于一般没人用 我注释掉了 +# Suffix: +# 1: +# text: '[变量1]' +# tip: +# - '变量1提示' +# click: +# type: 'COMMAND' +# command: 'say 命令执行' +# 同样可以添加多个 +# 2: \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6c3e536..532a562 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -16,8 +16,8 @@ commands: permission: ${project.artifactId}.reload permission-message: §c你没有 的权限来执行此命令! permissions: - ${project.artifactId}.use: - description: ${project.artifactId} 使用! + ${project.artifactId}.default: + description: 默认格式权限! default: true ${project.artifactId}.reload: description: 重新载入插件!