diff --git a/src/com/loohp/interactivechat/Listeners/Events.java b/src/com/loohp/interactivechat/Listeners/Events.java index c46c80d9..894fa28e 100644 --- a/src/com/loohp/interactivechat/Listeners/Events.java +++ b/src/com/loohp/interactivechat/Listeners/Events.java @@ -1,8 +1,9 @@ package com.loohp.interactivechat.Listeners; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import org.bukkit.Bukkit; @@ -172,30 +173,42 @@ private void checkMention(AsyncPlayerChatEvent event) { String message = event.getMessage(); Player sender = event.getPlayer(); if (InteractiveChat.AllowMention == true && sender.hasPermission("interactivechat.mention.player")) { + Map playernames = new HashMap<>(); for (Player player : Bukkit.getOnlinePlayers()) { - List playernames = new ArrayList(); - playernames.add(ChatColorUtils.stripColor(player.getName())); + playernames.put(ChatColorUtils.stripColor(player.getName()), player.getUniqueId()); if (!player.getName().equals(player.getDisplayName())) { - playernames.add(ChatColorUtils.stripColor(player.getDisplayName())); + playernames.put(ChatColorUtils.stripColor(player.getDisplayName()), player.getUniqueId()); } if (InteractiveChat.EssentialsHook) { if (InteractiveChat.essenNick.containsKey(player)) { - playernames.add(ChatColorUtils.stripColor(InteractiveChat.essenNick.get(player))); + playernames.put(ChatColorUtils.stripColor(InteractiveChat.essenNick.get(player)), player.getUniqueId()); } } - for (String name : playernames) { - int index = message.toLowerCase().indexOf(name.toLowerCase()); - if (index >= 0) { - char before = (index - 1) < 0 ? ' ' : message.charAt(index - 1); - char after = (index + name.length()) >= message.length() ? ' ' : message.charAt(index + name.length()); - if (String.valueOf(before).matches("[^a-zA-Z0-9]") && String.valueOf(after).matches("[^a-zA-Z0-9]")) { - if (!player.equals(sender)) { - InteractiveChat.mentionPair.put(player.getUniqueId(), new MentionPair(sender.getUniqueId(), player.getUniqueId(), InteractiveChat.mentionPair)); - } - break; - } - } - } + } + for (Entry entry : InteractiveChat.remotePlayers.entrySet()) { + playernames.put(ChatColorUtils.stripColor(entry.getValue().getName()), entry.getKey()); + } + for (Entry entry : playernames.entrySet()) { + String name = entry.getKey(); + UUID uuid = entry.getValue(); + int index = message.toLowerCase().indexOf(name.toLowerCase()); + if (index >= 0) { + char before = (index - 1) < 0 ? ' ' : message.charAt(index - 1); + char after = (index + name.length()) >= message.length() ? ' ' : message.charAt(index + name.length()); + if (String.valueOf(before).matches("[^a-zA-Z0-9]") && String.valueOf(after).matches("[^a-zA-Z0-9]")) { + if (!uuid.equals(sender.getUniqueId())) { + InteractiveChat.mentionPair.put(uuid, new MentionPair(sender.getUniqueId(), uuid, InteractiveChat.mentionPair)); + if (InteractiveChat.bungeecordMode) { + try { + BungeeMessageSender.forwardMentionPair(sender.getUniqueId(), uuid); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + break; + } + } } } } diff --git a/src/com/loohp/interactivechat/PluginMessaging/BungeeMessageListener.java b/src/com/loohp/interactivechat/PluginMessaging/BungeeMessageListener.java index d87c1b4f..e129e587 100644 --- a/src/com/loohp/interactivechat/PluginMessaging/BungeeMessageListener.java +++ b/src/com/loohp/interactivechat/PluginMessaging/BungeeMessageListener.java @@ -94,7 +94,7 @@ public void onPluginMessageReceived(String channel, Player pluginMessagingPlayer case 0x02: UUID sender = DataTypeIO.readUUID(input); UUID receiver = DataTypeIO.readUUID(input); - InteractiveChat.mentionPair.put(sender, new MentionPair(sender, receiver, InteractiveChat.mentionPair)); + InteractiveChat.mentionPair.put(receiver, new MentionPair(sender, receiver, InteractiveChat.mentionPair)); break; case 0x03: UUID uuid = DataTypeIO.readUUID(input);