From 2111d72387d65391382a7e972ef9f7d9bcc8e0b2 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 18 Oct 2026 19:58:34 +0200 Subject: [PATCH] Suggest /team info when clicking a team prefix Clicking the team prefix in the global/local chat or an event team prefix in the fight chat puts /team info into the chat input; the hover explains the click. --- .../steamwar/messages/BungeeCore.properties | 3 +- .../messages/BungeeCore_de.properties | 3 +- .../velocitycore/chat/ChatFormat.java | 35 ++++++++++++++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 4f988ef1..8e47001e 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -575,7 +575,7 @@ CHAT_EMPTY = §cDon\'t write meaningless empty messages. CHAT_SERVERTEAM_SENDER = §e{0} CHAT_SERVERTEAM = §8» §f{2} -CHAT_GLOBAL_SENDER = {3}{4}{5}{6}{0} +CHAT_GLOBAL_SENDER = {4}{5}{6}{0} CHAT_GLOBAL = §8» {7}{2} CHAT_TEAM_SENDER = §e{0} CHAT_TEAM = §8» §f{2} @@ -593,6 +593,7 @@ CHAT_FIGHT_REFEREE = §8» §e{0} CHAT_FIGHT_TEAM = §8» §f{0} CHAT_ICON = {0}{1} CHAT_HOVER_TEAM = §7Team: §e{0}\n§7Prefix: §r{1}{2} +CHAT_HOVER_TEAM_CLICK = §7Team: §e{0}\n§7Prefix: §r{1}{2}\n§8Click to insert §7/team info CHAT_HOVER_LOCAL = {0}\n§7Server: §e{1} CHAT_ICON_GLOBAL = 🌍 CHAT_ICON_LOCAL = ⌂ diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index d352cdf3..6f23220f 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -540,7 +540,7 @@ CHAT_EMPTY = §cSchreibe keine inhaltslosen Nachrichten. CHAT_SERVERTEAM_SENDER = §e{0} CHAT_SERVERTEAM = §8» §f{2} -CHAT_GLOBAL_SENDER = {3}{4}{5}{6}{0} +CHAT_GLOBAL_SENDER = {4}{5}{6}{0} CHAT_GLOBAL = §8» {7}{2} CHAT_TEAM_SENDER = §e{0} CHAT_TEAM = §8» §f{2} @@ -558,6 +558,7 @@ CHAT_FIGHT_REFEREE = §8» §e{0} CHAT_FIGHT_TEAM = §8» §f{0} CHAT_ICON = {0}{1} CHAT_HOVER_TEAM = §7Team: §e{0}\n§7Kürzel: §r{1}{2} +CHAT_HOVER_TEAM_CLICK = §7Team: §e{0}\n§7Kürzel: §r{1}{2}\n§8Klicke, um §7/team info §8einzufügen CHAT_HOVER_LOCAL = {0}\n§7Server: §e{1} CHAT_ICON_GLOBAL = 🌍 CHAT_ICON_LOCAL = ⌂ diff --git a/VelocityCore/src/de/steamwar/velocitycore/chat/ChatFormat.java b/VelocityCore/src/de/steamwar/velocitycore/chat/ChatFormat.java index 8f4a477e..91e5feda 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/chat/ChatFormat.java +++ b/VelocityCore/src/de/steamwar/velocitycore/chat/ChatFormat.java @@ -32,9 +32,11 @@ import de.steamwar.velocitycore.util.SteamwarPrefix; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextReplacementConfig; +import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import java.util.Arrays; +import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -42,6 +44,9 @@ public class ChatFormat { private static final Pattern MENTION = Pattern.compile("@(\\w{1,16})"); + // Formats that show the team prefix in front of the sender name + private static final Set TEAM_PREFIX_FORMATS = Set.of("CHAT_GLOBAL"); + private ChatFormat() {} /** @@ -52,12 +57,15 @@ public class ChatFormat { SteamwarUser user = sender.user(); UserPerm.Prefix prefix = user.prefix(); - String teamPrefix = ""; - if (user.hasPerm(UserPerm.TEAM) && useSwPrefix(user)) { - teamPrefix = "§eS§8W "; - } else if (user.getTeam() != 0) { - Team team = Team.byId(user.getTeam()); - teamPrefix = "§" + team.getTeamColor() + team.getTeamKuerzel() + " "; + // The team prefix is its own component, so that clicking it suggests /team info + Component teamPrefix = Component.empty(); + if (TEAM_PREFIX_FORMATS.contains(format)) { + if (useSwPrefix(user)) { + teamPrefix = withTeamHover(receiver, user, Chatter.SERIALIZER.deserialize("§eS§8W")).append(Component.text(" ")); + } else if (user.getTeam() != 0) { + Team team = Team.byId(user.getTeam()); + teamPrefix = clickableTeam(receiver, team, Chatter.SERIALIZER.deserialize("§" + team.getTeamColor() + team.getTeamKuerzel())).append(Component.text(" ")); + } } String chatColorCode = user.hasPerm(UserPerm.TEAM) ? "§f" : "§7"; @@ -65,14 +73,14 @@ public class ChatFormat { user, msgReceiver == null ? receiver : msgReceiver, highlightMentions(message, chatColorCode, receiver), - teamPrefix, + "", "", prefix == UserPerm.emptyPrefix ? "§f" : prefix.getColorCode(), prefix.getChatPrefix().length() == 0 ? "§f" : prefix.getChatPrefix() + " ", chatColorCode}; 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(); + return Component.text().append(teamPrefix).append(senderPart).append(receiver.parse(new Message(format, params))).build(); } /** @@ -87,7 +95,7 @@ public class ChatFormat { Component team = Chatter.SERIALIZER.deserialize(coloredTeamName); Team eventTeam = ChatManager.eventTeam(server, coloredTeamName); if (eventTeam != null) { - team = team.hoverEvent(HoverEvent.showText(teamHover(receiver, eventTeam))); + team = clickableTeam(receiver, eventTeam, team); } line.append(team).append(Component.text(" ")); nameColor = coloredTeamName.length() >= 2 && coloredTeamName.charAt(0) == '§' ? coloredTeamName.substring(0, 2) : ""; @@ -110,6 +118,15 @@ public class ChatFormat { return component.hoverEvent(HoverEvent.showText(teamHover(receiver, Team.byId(user.getTeam())))); } + /** + * Shows the team on hover and suggests {@code /team info} for it on click. + */ + private static Component clickableTeam(Chatter receiver, Team team, Component component) { + return component + .hoverEvent(HoverEvent.showText(receiver.parse(new Message("CHAT_HOVER_TEAM_CLICK", team.getTeamName(), "§" + team.getTeamColor(), team.getTeamKuerzel())))) + .clickEvent(ClickEvent.suggestCommand("/team info " + team.getTeamKuerzel())); + } + private static Component teamHover(Chatter receiver, Team team) { return receiver.parse(new Message("CHAT_HOVER_TEAM", team.getTeamName(), "§" + team.getTeamColor(), team.getTeamKuerzel())); }