SteamWar/BungeeCore
Archiviert
13
2

Merge pull request 'Improve @Ping a lot' (#195) from new_@ping into master

Reviewed-on: #195
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2021-04-10 18:38:09 +02:00
Commit fc20d9c671
3 geänderte Dateien mit 39 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -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));
}
}
}

Datei anzeigen

@ -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));
}
}
}

Datei anzeigen

@ -166,22 +166,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 +200,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<String> suggestions = e.getSuggestions();
@ -226,6 +237,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()){