diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 744541237..c9db69bb8 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -585,10 +585,14 @@ CHAT_TEAM = §8» §f{2} CHAT_MSG_SENDER = §e{0} CHAT_MSG = §8»§e{1} §7{2} CHAT_SPECIAL_ALERT = §e{0}§8»§e{1} §7{2} -CHAT_FIGHT_PARTICIPANT = {0} {1}§8» §7{2} -CHAT_FIGHT_SPECTATOR = §7{0}§8» §7{1} -CHAT_FIGHT_REFEREE = §e{0}§8» §e{1} -CHAT_FIGHT_TEAM = {0} {1}§8» §f{2} +CHAT_FIGHT_PARTICIPANT_SENDER = {0}{1} +CHAT_FIGHT_PARTICIPANT = §8» §7{0} +CHAT_FIGHT_SPECTATOR_SENDER = §7{1} +CHAT_FIGHT_SPECTATOR = §8» §7{0} +CHAT_FIGHT_REFEREE_SENDER = §e{1} +CHAT_FIGHT_REFEREE = §8» §e{0} +CHAT_FIGHT_TEAM_SENDER = {0}{1} +CHAT_FIGHT_TEAM = §8» §f{0} CHAT_ICON = {0}{1} CHAT_HOVER_TEAM = §7Team: §e{0}\n§7Prefix: §r{1}{2} CHAT_ICON_GLOBAL = 🌍 @@ -610,7 +614,6 @@ CHAT_CHANNEL_ALERT = §cAlert CHAT_CHANNEL_LOCAL = §eLocal CHAT_CHANNEL_CURRENT = §7You are writing into §e{0}§7. CHAT_CHANNEL_SWITCHED = §7You are now writing into §e{0}§7. -CHAT_CHANNEL_CLOSED = §e{0} §7was closed. CHAT_CHANNEL_NOT_SWITCHABLE = §cYou cannot write into this channel by default. CHAT_NO_WRITE = §cYou cannot write into this channel. CHAT_FIGHT_NO_TEAM = §cYou are not in a fight team. diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index 437a53667..091998787 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -550,10 +550,14 @@ CHAT_TEAM = §8» §f{2} CHAT_MSG_SENDER = §e{0} CHAT_MSG = §8»§e{1} §7{2} CHAT_SPECIAL_ALERT = §e{0}§8»§e{1} §7{2} -CHAT_FIGHT_PARTICIPANT = {0} {1}§8» §7{2} -CHAT_FIGHT_SPECTATOR = §7{0}§8» §7{1} -CHAT_FIGHT_REFEREE = §e{0}§8» §e{1} -CHAT_FIGHT_TEAM = {0} {1}§8» §f{2} +CHAT_FIGHT_PARTICIPANT_SENDER = {0}{1} +CHAT_FIGHT_PARTICIPANT = §8» §7{0} +CHAT_FIGHT_SPECTATOR_SENDER = §7{1} +CHAT_FIGHT_SPECTATOR = §8» §7{0} +CHAT_FIGHT_REFEREE_SENDER = §e{1} +CHAT_FIGHT_REFEREE = §8» §e{0} +CHAT_FIGHT_TEAM_SENDER = {0}{1} +CHAT_FIGHT_TEAM = §8» §f{0} CHAT_ICON = {0}{1} CHAT_HOVER_TEAM = §7Team: §e{0}\n§7Kürzel: §r{1}{2} CHAT_ICON_GLOBAL = 🌍 @@ -575,7 +579,6 @@ CHAT_CHANNEL_ALERT = §cAlert CHAT_CHANNEL_LOCAL = §eLokal CHAT_CHANNEL_CURRENT = §7Du schreibst in §e{0}§7. CHAT_CHANNEL_SWITCHED = §7Du schreibst jetzt in §e{0}§7. -CHAT_CHANNEL_CLOSED = §e{0} §7wurde geschlossen. CHAT_CHANNEL_NOT_SWITCHABLE = §cIn diesen Kanal kannst du nicht standardmäßig schreiben. CHAT_NO_WRITE = §cDu kannst nicht in diesen Kanal schreiben. CHAT_FIGHT_NO_TEAM = §cDu bist in keinem Kampfteam. diff --git a/VelocityCore/src/de/steamwar/velocitycore/chat/ChatFormat.java b/VelocityCore/src/de/steamwar/velocitycore/chat/ChatFormat.java index aeb8064e9..ad38e020c 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/chat/ChatFormat.java +++ b/VelocityCore/src/de/steamwar/velocitycore/chat/ChatFormat.java @@ -20,6 +20,7 @@ package de.steamwar.velocitycore.chat; +import com.velocitypowered.api.proxy.server.RegisteredServer; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.network.packets.server.PingPacket; @@ -29,6 +30,7 @@ import de.steamwar.sql.UserPerm; import de.steamwar.velocitycore.network.NetworkSender; import de.steamwar.velocitycore.util.SteamwarPrefix; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.HoverEvent; import java.util.Arrays; @@ -65,14 +67,49 @@ public class ChatFormat { prefix.getChatPrefix().length() == 0 ? "§f" : prefix.getChatPrefix() + " ", chatColorCode}; - Component senderPart = receiver.parse(new Message(format + "_SENDER", params)); - if (user.getTeam() != 0) { - Team team = Team.byId(user.getTeam()); - senderPart = senderPart.hoverEvent(HoverEvent.showText(receiver.parse(new Message("CHAT_HOVER_TEAM", team.getTeamName(), "§" + team.getTeamColor(), team.getTeamKuerzel())))); - } + Component senderPart = withTeamHover(receiver, user, receiver.parse(new Message(format + "_SENDER", params))); return Component.text().append(senderPart).append(receiver.parse(new Message(format, params))).build(); } + /** + * Formats a fight chat message. The fight team name is only hoverable in event fights, where it is the actual team. + * + * @param coloredTeamName the fight team of the sender, null if the sender is not in a fight team + */ + public static Component fight(Chatter receiver, RegisteredServer server, Chatter sender, String coloredTeamName, String format, String message) { + TextComponent.Builder line = Component.text(); + String nameColor = ""; + if (coloredTeamName != null) { + Component team = Chatter.SERIALIZER.deserialize(coloredTeamName); + Team eventTeam = ChatManager.eventTeam(server, coloredTeamName); + if (eventTeam != null) { + team = team.hoverEvent(HoverEvent.showText(teamHover(receiver, eventTeam))); + } + line.append(team).append(Component.text(" ")); + nameColor = coloredTeamName.length() >= 2 && coloredTeamName.charAt(0) == '§' ? coloredTeamName.substring(0, 2) : ""; + } + + line.append(withTeamHover(receiver, sender.user(), receiver.parse(new Message(format + "_SENDER", nameColor, sender.user())))); + line.append(receiver.parse(new Message(format, message))); + return line.build(); + } + + /** + * Shows the team of the user when hovering the component, the SteamWar team for server team members using the SW prefix. + */ + public static Component withTeamHover(Chatter receiver, SteamwarUser user, Component component) { + if (useSwPrefix(user)) { + return component.hoverEvent(HoverEvent.showText(receiver.parse(new Message("CHAT_HOVER_TEAM", "SteamWar", "§e", "S§8W")))); + } + if (user.getTeam() == 0) return component; + + return component.hoverEvent(HoverEvent.showText(teamHover(receiver, Team.byId(user.getTeam())))); + } + + private static Component teamHover(Chatter receiver, Team team) { + return receiver.parse(new Message("CHAT_HOVER_TEAM", team.getTeamName(), "§" + team.getTeamColor(), team.getTeamKuerzel())); + } + private static boolean useSwPrefix(SteamwarUser user) { if (!user.hasPerm(UserPerm.TEAM)) { return false; diff --git a/VelocityCore/src/de/steamwar/velocitycore/chat/ChatManager.java b/VelocityCore/src/de/steamwar/velocitycore/chat/ChatManager.java index a437532a1..c8565b8e1 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/chat/ChatManager.java +++ b/VelocityCore/src/de/steamwar/velocitycore/chat/ChatManager.java @@ -33,6 +33,7 @@ import de.steamwar.network.packets.common.FightInfoPacket; import de.steamwar.persistent.Subserver; import de.steamwar.sql.Event; import de.steamwar.sql.Referee; +import de.steamwar.sql.Team; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserConfig; import de.steamwar.sql.UserPerm; @@ -221,6 +222,23 @@ public class ChatManager extends BasicListener { return fightInfos.get(server); } + /** + * @return the team of an event fight on the server whose colored name is shown, null if the server runs no event fight + */ + static Team eventTeam(RegisteredServer server, String coloredTeamName) { + Subserver subserver = Subserver.getSubserver(server.getServerInfo()); + if (subserver == null) return null; + + String kuerzel = coloredTeamName.replaceAll("§.", ""); + for (Map.Entry entry : new ArrayList<>(EventStarter.getEventServer().entrySet())) { + if (entry.getValue() != subserver) continue; + + Team team = Team.byId(entry.getKey()); + if (team != null && team.getTeamKuerzel().equals(kuerzel)) return team; + } + return null; + } + /** * Updates the fight teams of an arena. Players who just joined a fight team write into the fight chat by default. */ @@ -382,19 +400,6 @@ public class ChatManager extends BasicListener { spies.remove(uuid); hidden.remove(uuid); - Iterator it = directs.iterator(); - while (it.hasNext()) { - DirectChannel channel = it.next(); - if (!channel.contains(uuid)) continue; - it.remove(); - - Player partner = VelocityCore.getProxy().getPlayer(channel.partner(uuid)).orElse(null); - if (partner != null && defaults.get(partner.getUniqueId()) == channel) { - PlayerChatter chatter = Chatter.of(partner); - chatter.system("CHAT_CHANNEL_CLOSED", channel.tag(chatter)); - defaults.put(partner.getUniqueId(), resolvePersisted(partner, currentServer(partner).orElse(null))); - chatter.system("CHAT_CHANNEL_SWITCHED", defaults.get(partner.getUniqueId()).tag(chatter)); - } - } + directs.removeIf(channel -> channel.contains(uuid)); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/chat/DirectChannel.java b/VelocityCore/src/de/steamwar/velocitycore/chat/DirectChannel.java index 3695c7015..f0a79923e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/chat/DirectChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/chat/DirectChannel.java @@ -60,6 +60,11 @@ public class DirectChannel extends ChatChannel { return new Message("CHAT_CHANNEL_MSG", SteamwarUser.get(partner(receiver.user().getUUID()))); } + @Override + public boolean switchable() { + return false; + } + @Override protected Message icon(Chatter receiver) { return new Message("CHAT_ICON_MSG"); diff --git a/VelocityCore/src/de/steamwar/velocitycore/chat/FightTeamChannel.java b/VelocityCore/src/de/steamwar/velocitycore/chat/FightTeamChannel.java index 3768fa75c..869d7c242 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/chat/FightTeamChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/chat/FightTeamChannel.java @@ -102,7 +102,7 @@ public class FightTeamChannel extends ChatChannel { @Override protected Component format(Chatter receiver, Chatter sender, String message) { - return receiver.parse(new Message("CHAT_FIGHT_TEAM", teamName(), sender.user(), ChatFormat.highlightMentions(message, "§f", receiver))); + return ChatFormat.fight(receiver, server, sender, teamName(), "CHAT_FIGHT_TEAM", ChatFormat.highlightMentions(message, "§f", receiver)); } @Override diff --git a/VelocityCore/src/de/steamwar/velocitycore/chat/LocalChannel.java b/VelocityCore/src/de/steamwar/velocitycore/chat/LocalChannel.java index 27f7b6363..12aece2ae 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/chat/LocalChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/chat/LocalChannel.java @@ -104,13 +104,13 @@ public class LocalChannel extends ChatChannel { FightInfoPacket info = ChatManager.getFightInfo(server); int id = sender.user().getId(); if (info != null && info.getBluePlayers().contains(id)) { - return receiver.parse(new Message("CHAT_FIGHT_PARTICIPANT", info.getBlueName(), sender.user(), highlighted)); + return ChatFormat.fight(receiver, server, sender, info.getBlueName(), "CHAT_FIGHT_PARTICIPANT", highlighted); } else if (info != null && info.getRedPlayers().contains(id)) { - return receiver.parse(new Message("CHAT_FIGHT_PARTICIPANT", info.getRedName(), sender.user(), highlighted)); + return ChatFormat.fight(receiver, server, sender, info.getRedName(), "CHAT_FIGHT_PARTICIPANT", highlighted); } else if (ChatManager.isReferee(server, id)) { - return receiver.parse(new Message("CHAT_FIGHT_REFEREE", sender.user(), highlighted)); + return ChatFormat.fight(receiver, server, sender, null, "CHAT_FIGHT_REFEREE", highlighted); } - return receiver.parse(new Message("CHAT_FIGHT_SPECTATOR", sender.user(), highlighted)); + return ChatFormat.fight(receiver, server, sender, null, "CHAT_FIGHT_SPECTATOR", highlighted); } @Override diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/MsgCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/MsgCommand.java index 67cbd21a4..4db12170e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/MsgCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/MsgCommand.java @@ -24,7 +24,6 @@ import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import de.steamwar.messages.PlayerChatter; import de.steamwar.velocitycore.VelocityCore; -import de.steamwar.velocitycore.chat.ChatChannel; import de.steamwar.velocitycore.chat.ChatManager; import static de.steamwar.persistent.Storage.lastChats; @@ -37,7 +36,7 @@ public class MsgCommand extends SWCommand { } @Register(description = "MSG_USAGE") - public void genericCommand(PlayerChatter sender, @ErrorMessage(value = "MSG_OFFLINE") Player target, String... message) { + public void genericCommand(PlayerChatter sender, @ErrorMessage(value = "MSG_OFFLINE") Player target, @ErrorMessage(value = "MSG_USAGE", allowEAs = false) String... message) { msg(sender, target, message); } @@ -47,12 +46,7 @@ public class MsgCommand extends SWCommand { return; } - ChatChannel channel = ChatManager.direct(sender.user().getUUID(), target.getUniqueId()); - if (args.length == 0) { - ChatManager.switchTo(sender, channel); - } else { - channel.send(sender, String.join(" ", args)); - } + ChatManager.direct(sender.user().getUUID(), target.getUniqueId()).send(sender, String.join(" ", args)); } public static void remove(Player player) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/RCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/RCommand.java index 65582e856..ae86f2492 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/RCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/RCommand.java @@ -33,7 +33,7 @@ public class RCommand extends SWCommand { } @Register(description = "R_USAGE") - public void genericCommand(PlayerChatter sender, String... message) { + public void genericCommand(PlayerChatter sender, @ErrorMessage(value = "R_USAGE", allowEAs = false) String... message) { MsgCommand.msg(sender, lastChats.get(sender.getPlayer()), message); } }