4
1
mirror of https://e.coding.net/circlecloud/MiaoChat.git synced 2024-11-14 13:28:46 +00:00

feat: 添加多个聊天格式处理

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-09 17:24:51 +08:00
parent 26fcb448c9
commit f41da56c62
8 changed files with 185 additions and 63 deletions

View File

@ -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配置文件已重载!");
}
}

View File

@ -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<ChatMessagePart> suffixs;
private ChatMessagePart player;
public ChatConfig() {
config = P.getConfig();
public ChatConfig(final FileConfig cfg) {
config = cfg;
prefixs = new LinkedList<>();
suffixs = new LinkedList<>();
reload();

View File

@ -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;
}
}

View File

@ -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<String, ChatConfig> formats = new HashMap<>();
public Config() {
reload();
}
/**
* 获得玩家可用的消息处理
*
* @param player
* @return {@link ChatConfig}
*/
public ChatConfig getChatConfig(final Player player) {
return null;
}
public void reload() {
}
}

View File

@ -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()) {

View File

@ -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 命令执行'
#配置文件版本号 请勿修改
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

View File

@ -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:

View File

@ -16,8 +16,8 @@ commands:
permission: ${project.artifactId}.reload
permission-message: §c你没有 <permission> 的权限来执行此命令!
permissions:
${project.artifactId}.use:
description: ${project.artifactId} 使用!
${project.artifactId}.default:
description: 默认格式权限!
default: true
${project.artifactId}.reload:
description: 重新载入插件!