|
6 | 6 | import cn.handyplus.chat.util.ConfigUtil;
|
7 | 7 | import cn.handyplus.lib.core.CollUtil;
|
8 | 8 | import cn.handyplus.lib.core.JsonUtil;
|
| 9 | +import cn.handyplus.lib.core.PatternUtil; |
9 | 10 | import cn.handyplus.lib.core.StrUtil;
|
10 | 11 | import cn.handyplus.lib.expand.adapter.HandySchedulerUtil;
|
11 | 12 | import cn.handyplus.lib.expand.adapter.PlayerSchedulerUtil;
|
|
14 | 15 | import cn.handyplus.lib.util.MessageUtil;
|
15 | 16 | import cn.handyplus.lib.util.RgbTextUtil;
|
16 | 17 | import net.md_5.bungee.api.chat.BaseComponent;
|
17 |
| -import org.bukkit.Bukkit; |
18 | 18 | import org.bukkit.ChatColor;
|
19 | 19 | import org.bukkit.Sound;
|
20 | 20 | import org.bukkit.entity.Player;
|
@@ -65,9 +65,12 @@ public synchronized static void sendTextMsg(BcUtil.BcMessageParam param, boolean
|
65 | 65 | }
|
66 | 66 | MessageUtil.sendMessage(onlinePlayer, textComponent);
|
67 | 67 | // 如果开启艾特,发送消息
|
68 |
| - if (ChatConstants.CHAT_TYPE.equals(param.getType()) && ConfigUtil.CHAT_CONFIG.getBoolean("at.enable") && chatParam.getMessage().contains(onlinePlayer.getName())) { |
69 |
| - String sound = ConfigUtil.CHAT_CONFIG.getString("at.sound"); |
70 |
| - playSound(onlinePlayer, sound); |
| 68 | + if (ChatConstants.CHAT_TYPE.equals(param.getType()) && ConfigUtil.CHAT_CONFIG.getBoolean("at.enable")) { |
| 69 | + // 获取艾特玩家 |
| 70 | + if (CollUtil.isNotEmpty(chatParam.getMentionedPlayers()) && chatParam.getMentionedPlayers().contains(onlinePlayer.getName())) { |
| 71 | + String sound = ConfigUtil.CHAT_CONFIG.getString("at.sound"); |
| 72 | + playSound(onlinePlayer, sound); |
| 73 | + } |
71 | 74 | }
|
72 | 75 | }
|
73 | 76 | // 控制台消息
|
@@ -240,20 +243,26 @@ private static List<String> replaceStr(Player player, String channelName, List<S
|
240 | 243 | }
|
241 | 244 |
|
242 | 245 | /**
|
243 |
| - * @param message 消息 |
| 246 | + * 处理@人 |
| 247 | + * |
| 248 | + * @param mentionedPlayers 被@的人 |
| 249 | + * @param message 消息 |
244 | 250 | * @return 新消息
|
245 |
| - * @ 处理 |
246 | 251 | * @since 1.0.9
|
247 | 252 | */
|
248 |
| - public static String at(String message) { |
| 253 | + public static String at(List<String> mentionedPlayers, String message) { |
249 | 254 | boolean enable = ConfigUtil.CHAT_CONFIG.getBoolean("at.enable");
|
250 | 255 | if (!enable) {
|
251 | 256 | return message;
|
252 | 257 | }
|
253 |
| - for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { |
254 |
| - if (message.contains("@" + onlinePlayer.getName())) { |
255 |
| - message = message.replace("@" + onlinePlayer.getName(), ChatColor.BLUE + onlinePlayer.getName() + ChatColor.WHITE); |
256 |
| - } |
| 258 | + // 提取@的玩家名 |
| 259 | + mentionedPlayers.addAll(PatternUtil.extractAtTags(message)); |
| 260 | + if (CollUtil.isEmpty(mentionedPlayers)) { |
| 261 | + return message; |
| 262 | + } |
| 263 | + // 将 @玩家名 替换为高亮显示 |
| 264 | + for (String playerName : mentionedPlayers) { |
| 265 | + message = message.replaceAll("@" + playerName, ChatColor.BLUE + playerName + ChatColor.RESET); |
257 | 266 | }
|
258 | 267 | return message;
|
259 | 268 | }
|
|
0 commit comments