SteamWar/BungeeCore
Archiviert
13
2

Improve @Ping a lot

Dieser Commit ist enthalten in:
Chaoscaot 2021-04-04 18:35:28 +02:00
Ursprung fd2fbadc4f
Commit 1773d3df66
3 geänderte Dateien mit 40 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

@ -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<String> 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()){