diff --git a/pom.xml b/pom.xml index 3dfb34a..4c8f717 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.handyplus.chat PlayerChat - 1.1.4 + 1.1.5 一款有点好用的聊天插件 diff --git a/src/main/java/cn/handyplus/chat/command/player/LbCommand.java b/src/main/java/cn/handyplus/chat/command/LbCommand.java similarity index 98% rename from src/main/java/cn/handyplus/chat/command/player/LbCommand.java rename to src/main/java/cn/handyplus/chat/command/LbCommand.java index 3ee9c43..8ea9494 100644 --- a/src/main/java/cn/handyplus/chat/command/player/LbCommand.java +++ b/src/main/java/cn/handyplus/chat/command/LbCommand.java @@ -1,4 +1,4 @@ -package cn.handyplus.chat.command.player; +package cn.handyplus.chat.command; import cn.handyplus.chat.PlayerChat; import cn.handyplus.chat.core.HornUtil; diff --git a/src/main/java/cn/handyplus/chat/command/player/TellCommand.java b/src/main/java/cn/handyplus/chat/command/player/TellCommand.java new file mode 100644 index 0000000..139e80e --- /dev/null +++ b/src/main/java/cn/handyplus/chat/command/player/TellCommand.java @@ -0,0 +1,52 @@ +package cn.handyplus.chat.command.player; + +import cn.handyplus.chat.constants.ChatConstants; +import cn.handyplus.chat.listener.AsyncPlayerChatEventListener; +import cn.handyplus.chat.util.ConfigUtil; +import cn.handyplus.lib.command.IHandyCommandEvent; +import cn.handyplus.lib.util.AssertUtil; +import cn.handyplus.lib.util.BaseUtil; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * 私信 + * + * @author handy + */ +public class TellCommand implements IHandyCommandEvent { + + @Override + public String command() { + return "tell"; + } + + @Override + public String permission() { + return "playerChat.tell"; + } + + @Override + public boolean isAsync() { + return true; + } + + @Override + public void onCommand(CommandSender sender, Command cmd, String label, String[] args) { + // 参数是否正常 + AssertUtil.notTrue(args.length < 2, sender, ConfigUtil.LANG_CONFIG.getString("paramFailureMsg")); + // 是否为玩家 + Player player = AssertUtil.notPlayer(sender, BaseUtil.getMsgNotColor("noPlayerFailureMsg")); + // 接收人 + String playerName = args[1]; + // 获取消息 + StringBuilder message = new StringBuilder(); + for (int i = 2; i < args.length; i++) { + message.append(args[i]).append(" "); + } + // 发送消息 + AsyncPlayerChatEventListener.sendMsg(player, message.toString(), ChatConstants.TELL, playerName); + } + +} \ No newline at end of file diff --git a/src/main/java/cn/handyplus/chat/constants/ChatConstants.java b/src/main/java/cn/handyplus/chat/constants/ChatConstants.java index d567725..5a1cd5e 100644 --- a/src/main/java/cn/handyplus/chat/constants/ChatConstants.java +++ b/src/main/java/cn/handyplus/chat/constants/ChatConstants.java @@ -17,6 +17,11 @@ public abstract class ChatConstants { */ public final static String DEFAULT = "default"; + /** + * 私信频道 + */ + public static final String TELL = "tell"; + /** * 消息类型 */ diff --git a/src/main/java/cn/handyplus/chat/core/ChatUtil.java b/src/main/java/cn/handyplus/chat/core/ChatUtil.java index bce4705..3145787 100644 --- a/src/main/java/cn/handyplus/chat/core/ChatUtil.java +++ b/src/main/java/cn/handyplus/chat/core/ChatUtil.java @@ -58,6 +58,10 @@ private synchronized static void sendTextMsg(BcUtil.BcMessageParam param, boolea } // 根据频道发送消息 for (Player onlinePlayer : ChannelUtil.getChannelPlayer(channel)) { + // 判断是否开启私信 + if (StrUtil.isNotEmpty(chatParam.getTellPlayerName()) && !onlinePlayer.getName().equals(chatParam.getTellPlayerName())) { + continue; + } MessageUtil.sendMessage(onlinePlayer, textComponent); // 如果开启艾特,发送消息 if (ChatConstants.CHAT_TYPE.equals(param.getType()) && ConfigUtil.CHAT_CONFIG.getBoolean("at.enable") && chatParam.getMessage().contains(onlinePlayer.getName())) { diff --git a/src/main/java/cn/handyplus/chat/listener/AsyncPlayerChatEventListener.java b/src/main/java/cn/handyplus/chat/listener/AsyncPlayerChatEventListener.java index ac7640a..96e21f1 100644 --- a/src/main/java/cn/handyplus/chat/listener/AsyncPlayerChatEventListener.java +++ b/src/main/java/cn/handyplus/chat/listener/AsyncPlayerChatEventListener.java @@ -58,12 +58,28 @@ public void onChat(AsyncPlayerChatEvent event) { } // 取消事件 event.setCancelled(true); + // 发送消息 + sendMsg(player, event.getMessage(), channel); + } + + public static void sendMsg(Player player, String message, String channel) { + sendMsg(player, message, channel, null); + } + /** + * 发送消息 + * + * @param player 玩家 + * @param message 消息 + * @param channel 渠道 + * @param tellPlayerName 接收人 + * @since 1.1.5 + */ + public static void sendMsg(Player player, String message, String channel, String tellPlayerName) { // 聊天频率处理 - if (!this.chatTimeCheck(player)) { + if (chatTimeCheck(player)) { return; } - // 参数构建 BcUtil.BcMessageParam param = new BcUtil.BcMessageParam(); param.setPluginName(PlayerChat.getInstance().getName()); @@ -74,11 +90,14 @@ public void onChat(AsyncPlayerChatEvent event) { if (chatParam == null) { return; } - + // 添加接收人 1.1.5 + chatParam.setTellPlayerName(tellPlayerName); // 内容黑名单处理 - String message = this.blackListCheck(event); + message = blackListCheck(message); + // @处理 + message = ChatUtil.at(message); // 消息内容 - chatParam.setMessage(ChatUtil.at(message)); + chatParam.setMessage(message); // 有权限进行颜色代码处理 chatParam.setHasColor(player.hasPermission("playerChat.color")); chatParam.setChannel(channel); @@ -91,11 +110,10 @@ public void onChat(AsyncPlayerChatEvent event) { /** * 替换黑名单词语为* * - * @param event 事件 + * @param message 消息 * @return 健康消息 */ - private String blackListCheck(AsyncPlayerChatEvent event) { - String message = event.getMessage(); + private static String blackListCheck(String message) { List blacklist = ConfigUtil.CONFIG.getStringList("blacklist"); if (CollUtil.isNotEmpty(blacklist)) { for (String blackMsg : blacklist) { @@ -113,18 +131,18 @@ private String blackListCheck(AsyncPlayerChatEvent event) { * @param player 玩家 * @return true 可 */ - private boolean chatTimeCheck(Player player) { + private static boolean chatTimeCheck(Player player) { int chatTime = HandyPermissionUtil.getReverseIntNumber(player, ConfigUtil.CONFIG, "chatTime"); if (ChatConstants.PLAYER_CHAT_TIME.containsKey(player.getUniqueId())) { long keepAlive = (System.currentTimeMillis() - ChatConstants.PLAYER_CHAT_TIME.get(player.getUniqueId())) / 1000L; if (keepAlive < chatTime) { String waitTimeMsg = BaseUtil.getLangMsg("chatTime").replace("${chatTime}", (chatTime - keepAlive) + ""); MessageUtil.sendMessage(player, waitTimeMsg); - return false; + return true; } } ChatConstants.PLAYER_CHAT_TIME.put(player.getUniqueId(), System.currentTimeMillis()); - return true; + return false; } /** @@ -149,7 +167,7 @@ public void onItemChat(AsyncPlayerChatEvent event) { event.setCancelled(true); Player player = event.getPlayer(); // 聊天频率处理 - if (!this.chatTimeCheck(player)) { + if (chatTimeCheck(player)) { return; } // 获取物品参数 diff --git a/src/main/java/cn/handyplus/chat/listener/ChatPluginMessageListener.java b/src/main/java/cn/handyplus/chat/listener/ChatPluginMessageListener.java index 35cbab3..10e3f89 100644 --- a/src/main/java/cn/handyplus/chat/listener/ChatPluginMessageListener.java +++ b/src/main/java/cn/handyplus/chat/listener/ChatPluginMessageListener.java @@ -49,7 +49,7 @@ public void unregister() { * @param message 消息 */ @Override - public void onPluginMessageReceived(@NotNull String channel,@NotNull Player player, byte[] message) { + public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] message) { // 自定义消息处理 String server = ConfigUtil.CONFIG.getString("server"); MessageUtil.sendConsoleDebugMessage("子服:" + server + "收到消息"); diff --git a/src/main/java/cn/handyplus/chat/param/ChatParam.java b/src/main/java/cn/handyplus/chat/param/ChatParam.java index 44f158a..b2ccc7d 100644 --- a/src/main/java/cn/handyplus/chat/param/ChatParam.java +++ b/src/main/java/cn/handyplus/chat/param/ChatParam.java @@ -81,4 +81,11 @@ public class ChatParam { */ private Integer itemId; + /** + * 接收人 + * + * @since 1.1.5 + */ + private String tellPlayerName; + } diff --git a/src/main/resources/chat.yml b/src/main/resources/chat.yml index 8a5489c..47de928 100644 --- a/src/main/resources/chat.yml +++ b/src/main/resources/chat.yml @@ -49,6 +49,37 @@ chat: - '&7时间: %server_time_h:mm:ss a%' # 点击后执行的命令 click: '' + # 私信频道(严禁删除本频道) + tell: + # 是否开启 + enable: true + # 频道名称 + name: "&7[&a私信频道&7]" + # 聊天格式 支持变量 + format: + # 聊天前缀 + prefix: + text: '${channel}%playerTitle_use%' + # 1.16+可用hover + hover: + - '&8▪ &6所在聊天频道: ${channel}' + - '&8▪ &6点击可执行命令/spawn' + # 点击后执行的命令 + click: '/spawn' + # 聊天玩家名 + player: + text: '&f${player}&7: ' + hover: + - '快点击tpa我啦~' + # 点击后执行的命令 + click: '/tpa ${player}' + # 聊天内容 + msg: + text: '&f' + hover: + - '&7时间: %server_time_h:mm:ss a%' + # 点击后执行的命令 + click: '' # VIP频道 vip: # 是否开启 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3f64b45..b449f78 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: PlayerChat main: cn.handyplus.chat.PlayerChat -version: 1.1.4 +version: 1.1.5 author: handy api-version: 1.13 softdepend: [ PlaceholderAPI ] @@ -26,6 +26,7 @@ permissions: playerChat.color: true playerChat.channel: true playerChat.item: true + playerChat.tell: true playerChat.reload: description: 重新加载配置 default: op @@ -55,4 +56,13 @@ permissions: default: true playerChat.use.default: description: 默认频道使用权限 + default: true + playerChat.tell: + description: 私聊权限 + default: op + playerChat.chat.tell: + description: 私信频道查看权限 + default: true + playerChat.use.tell: + description: 私信频道使用权限 default: true \ No newline at end of file