forked from circlecloud/MiaoChat
feat: 添加多个聊天格式处理
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
26fcb448c9
commit
f41da56c62
@ -3,7 +3,7 @@ package pw.yumc.MiaoChat;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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.MiaoChat.listeners.ChatListener;
|
||||||
import pw.yumc.YumCore.commands.CommandArgument;
|
import pw.yumc.YumCore.commands.CommandArgument;
|
||||||
import pw.yumc.YumCore.commands.CommandExecutor;
|
import pw.yumc.YumCore.commands.CommandExecutor;
|
||||||
@ -13,15 +13,15 @@ import pw.yumc.YumCore.commands.annotation.Help;
|
|||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
|
|
||||||
public class MiaoChat extends JavaPlugin implements CommandExecutor {
|
public class MiaoChat extends JavaPlugin implements CommandExecutor {
|
||||||
private ChatConfig chatConfig;
|
private FileConfig cfg;
|
||||||
private FileConfig config;
|
private Config config;
|
||||||
|
|
||||||
public ChatConfig getChatConfig() {
|
|
||||||
return chatConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Config getConfigExt() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,15 +33,14 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
config = new FileConfig();
|
cfg = new FileConfig();
|
||||||
chatConfig = new ChatConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd(permission = "MiaoChat.reload")
|
@Cmd(permission = "MiaoChat.reload")
|
||||||
@Help("重载配置文件")
|
@Help("重载配置文件")
|
||||||
public void reload(final CommandArgument e) {
|
public void reload(final CommandArgument e) {
|
||||||
|
cfg.reload();
|
||||||
config.reload();
|
config.reload();
|
||||||
chatConfig.reload();
|
|
||||||
e.getSender().sendMessage("§a配置文件已重载!");
|
e.getSender().sendMessage("§a配置文件已重载!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package pw.yumc.MiaoChat.config;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
|
|
||||||
public class ChatConfig {
|
public class ChatConfig {
|
||||||
@ -14,8 +13,8 @@ public class ChatConfig {
|
|||||||
private final List<ChatMessagePart> suffixs;
|
private final List<ChatMessagePart> suffixs;
|
||||||
private ChatMessagePart player;
|
private ChatMessagePart player;
|
||||||
|
|
||||||
public ChatConfig() {
|
public ChatConfig(final FileConfig cfg) {
|
||||||
config = P.getConfig();
|
config = cfg;
|
||||||
prefixs = new LinkedList<>();
|
prefixs = new LinkedList<>();
|
||||||
suffixs = new LinkedList<>();
|
suffixs = new LinkedList<>();
|
||||||
reload();
|
reload();
|
||||||
|
51
src/main/java/pw/yumc/MiaoChat/config/ChatRule.java
Normal file
51
src/main/java/pw/yumc/MiaoChat/config/ChatRule.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
src/main/java/pw/yumc/MiaoChat/config/Config.java
Normal file
37
src/main/java/pw/yumc/MiaoChat/config/Config.java
Normal 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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -26,9 +26,12 @@ public class ChatListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChat(final AsyncPlayerChatEvent e) {
|
public void onChat(final AsyncPlayerChatEvent e) {
|
||||||
e.setCancelled(true);
|
|
||||||
final Player p = e.getPlayer();
|
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 String msg = e.getMessage();
|
||||||
final Tellraw tr = Tellraw.create();
|
final Tellraw tr = Tellraw.create();
|
||||||
for (final ChatMessagePart cmp : cc.getPrefixs()) {
|
for (final ChatMessagePart cmp : cc.getPrefixs()) {
|
||||||
|
@ -1,46 +1,25 @@
|
|||||||
#格式化配置
|
#配置文件版本号 请勿修改
|
||||||
Format:
|
Version: 1.0
|
||||||
#前缀配置 于玩家名称前
|
|
||||||
Prefix:
|
#格式列表
|
||||||
#顺序
|
Formats:
|
||||||
1:
|
#格式名称 对应当前文件夹下的default.yml
|
||||||
#文本 支持PAPI变量
|
default:
|
||||||
text: '&6[&a%player_world%&6]'
|
#优先级(将按照从小到大依次检测 比如 1-50 优先检测 1 符合则显示 不符合 检测 2 ...)
|
||||||
#悬浮提示 支持PAPI
|
index: 50
|
||||||
tip:
|
#权限
|
||||||
- '&6当前所在位置:'
|
permission: 'MiaoChat.default'
|
||||||
- '&6世界: &d%player_world%'
|
#范围(0为无限制)
|
||||||
- '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%'
|
range: 0
|
||||||
- ''
|
#解析物品(%i%=>手上物品,%0-9%快捷栏对应物品)
|
||||||
- '&c点击即可TP我!'
|
item: true
|
||||||
#点击操作
|
#格式名称 对应当前文件夹下的admin.yml
|
||||||
click:
|
admin:
|
||||||
#操作类型: [COMMAND,SUGGEST]
|
#优先级(将按照从小到大依次检测 比如 1-50 优先检测 1 符合则显示 不符合 检测 2 ...)
|
||||||
#COMMAND代表执行命令
|
index: 49
|
||||||
#SUGGEST代表命令补全
|
#权限
|
||||||
type: 'COMMAND'
|
permission: 'MiaoChat.reload'
|
||||||
#命令 支持PAPI
|
#范围(0为无限制)
|
||||||
command: '/tpa %player_name%'
|
range: 0
|
||||||
#玩家名称配置
|
#解析物品(%i%=>手上物品,%0-9%快捷栏对应物品)
|
||||||
Player:
|
item: true
|
||||||
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 命令执行'
|
|
54
src/main/resources/default.yml
Normal file
54
src/main/resources/default.yml
Normal 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:
|
@ -16,8 +16,8 @@ commands:
|
|||||||
permission: ${project.artifactId}.reload
|
permission: ${project.artifactId}.reload
|
||||||
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||||
permissions:
|
permissions:
|
||||||
${project.artifactId}.use:
|
${project.artifactId}.default:
|
||||||
description: ${project.artifactId} 使用!
|
description: 默认格式权限!
|
||||||
default: true
|
default: true
|
||||||
${project.artifactId}.reload:
|
${project.artifactId}.reload:
|
||||||
description: 重新载入插件!
|
description: 重新载入插件!
|
||||||
|
Loading…
Reference in New Issue
Block a user