Added tag feature

This commit is contained in:
Clément
2025-03-03 12:15:17 +01:00
parent 4b8adef72f
commit 5befdd3080
2 changed files with 8 additions and 1 deletions

View File

@@ -15,4 +15,8 @@ public class ANSIColor {
.replace("&y", GREY)
.replace("&n", RESET);
}
public static String tag(String message, String chatter){
return message.replaceAll("(@" + chatter + ")", "\u001B[44;30m$1\u001B[49;39m" );
}
}

View File

@@ -10,6 +10,7 @@ import java.util.Map;
import network.PacketHandler;
import network.SocketReader;
import network.protocol.ANSIColor;
import network.protocol.Packet;
import network.protocol.packets.ChatMessagePacket;
import network.protocol.packets.SendChatMessagePacket;
@@ -81,7 +82,9 @@ public class Server implements PacketHandler {
public boolean sendToRoom(String roomName, ChatMessagePacket packet) {
if (roomName != null && rooms.containsKey(roomName)) {
rooms.get(roomName).forEach(con -> con.sendPacket(packet));
rooms.get(roomName).forEach(con -> con.sendPacket(
new ChatMessagePacket(packet.getTime(), packet.getChatter(), ANSIColor.tag(packet.getContent(), con.getChatterName()))
));
return true;
}
return false;