From 1773d3df66b1ed8d1bc60a9e6b13364657c09e2e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 4 Apr 2021 18:35:28 +0200 Subject: [PATCH] Improve @Ping a lot --- .../commands/ServerTeamchatCommand.java | 3 +- .../bungeecore/commands/TeamchatCommand.java | 3 +- .../bungeecore/listeners/ChatListener.java | 49 ++++++++++++++----- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java index 90a6139..0aca552 100644 --- a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.listeners.ChatListener; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; @@ -56,7 +57,7 @@ public class ServerTeamchatCommand extends BasicCommand { for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ if ((target.hasPermission("bungeecore.teamchat")) && target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){ - Message.sendPrefixless("STC_FORMAT", target, sender.getName(), message); + Message.sendPrefixless("STC_FORMAT", target, sender.getName(), ChatListener.parseAtMessage(message, "§r", target)); } } } diff --git a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java index f5d17f5..d85ac6e 100644 --- a/src/de/steamwar/bungeecore/commands/TeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamchatCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.listeners.ChatListener; import de.steamwar.bungeecore.sql.SteamwarUser; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; @@ -59,7 +60,7 @@ public class TeamchatCommand extends BasicCommand { SteamwarUser targetuser = SteamwarUser.get(target.getUniqueId()); if (targetuser.getTeam() == user.getTeam() && target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){ - Message.sendPrefixless("TC_FORMAT", target, player.getName(), msg); + Message.sendPrefixless("TC_FORMAT", target, player.getName(), ChatListener.parseAtMessage(msg, "§f", target)); } } } diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 2a5e922..f31eb83 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -35,6 +35,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.TabCompleteEvent; import net.md_5.bungee.api.event.TabCompleteResponseEvent; +import net.md_5.bungee.api.event.TargetedEvent; import net.md_5.bungee.api.scheduler.TaskScheduler; import net.md_5.bungee.event.EventHandler; @@ -166,22 +167,11 @@ public class ChatListener extends BasicListener { msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg; } - String[] msgSplits = msg.split(" "); - StringBuilder builder = new StringBuilder(); - for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ Subserver targetServer = Subserver.getSubserver(target); if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue; - for (String curr : msgSplits) { - if(curr.equalsIgnoreCase("@" + target.getName())) { - builder.append("§e@").append(target.getName()).append(chatcolor).append(" "); - new PingPacket(SteamwarUser.get(target).getId()).send(target); - }else { - builder.append(curr).append(" "); - } - } - BungeeCore.send(target, ChatMessageType.CHAT, builder.toString()); - builder = new StringBuilder(); + + BungeeCore.send(target, ChatMessageType.CHAT, parseAtMessage(msg, chatcolor, target)); } BungeeCore.log(sender.getServer().getInfo(), msg); } @@ -211,6 +201,28 @@ public class ChatListener extends BasicListener { e.setMessage(e.getMessage().substring(command[0].length() + 1)); } + public static String parseAtMessage(String message, String returnColor, ProxiedPlayer player) { + if(!message.contains("@")) { + return message; + } + + StringBuilder builder = new StringBuilder(); + for (String curr : message.split(" ")) { + if(curr.toLowerCase().startsWith("@" + player.getName().toLowerCase())) { + new PingPacket(SteamwarUser.get(player).getId()).send(player); + builder.append("§e@") + .append(player.getName()) + .append(returnColor) + .append(curr.substring(player.getName().length() + 1)) + .append(" "); + }else { + builder.append(curr) + .append(" "); + } + } + return builder.toString(); + } + @EventHandler public void onTabCompleteEvent(TabCompleteEvent e){ List suggestions = e.getSuggestions(); @@ -226,6 +238,17 @@ public class ChatListener extends BasicListener { suggestions.add(name); } } + + if(last.startsWith("@")) { + String plrName = last.replace("@", ""); + for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ + String name = player.getName(); + if ((plrName.isEmpty() || name.startsWith(plrName)) && !plrName.equalsIgnoreCase(name)) { + suggestions.add("@" + name); + } + } + } + if(e.getSender() instanceof ProxiedPlayer && cursor.length == 1 && cursor[0].startsWith("/")){ ProxiedPlayer player = (ProxiedPlayer) e.getSender(); for(String cmd : BungeeCore.commands.keySet()){