forked from SteamWar/SteamWar
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 <shorthand> into the chat input; the hover explains the click.
This commit is contained in:
@@ -575,7 +575,7 @@ CHAT_EMPTY = §cDon\'t write meaningless empty messages.
|
|||||||
|
|
||||||
CHAT_SERVERTEAM_SENDER = §e{0}
|
CHAT_SERVERTEAM_SENDER = §e{0}
|
||||||
CHAT_SERVERTEAM = §8» §f{2}
|
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_GLOBAL = §8» {7}{2}
|
||||||
CHAT_TEAM_SENDER = §e{0}
|
CHAT_TEAM_SENDER = §e{0}
|
||||||
CHAT_TEAM = §8» §f{2}
|
CHAT_TEAM = §8» §f{2}
|
||||||
@@ -593,6 +593,7 @@ CHAT_FIGHT_REFEREE = §8» §e{0}
|
|||||||
CHAT_FIGHT_TEAM = §8» §f{0}
|
CHAT_FIGHT_TEAM = §8» §f{0}
|
||||||
CHAT_ICON = {0}{1}
|
CHAT_ICON = {0}{1}
|
||||||
CHAT_HOVER_TEAM = §7Team: §e{0}\n§7Prefix: §r{1}{2}
|
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_HOVER_LOCAL = {0}\n§7Server: §e{1}
|
||||||
CHAT_ICON_GLOBAL = 🌍
|
CHAT_ICON_GLOBAL = 🌍
|
||||||
CHAT_ICON_LOCAL = ⌂
|
CHAT_ICON_LOCAL = ⌂
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ CHAT_EMPTY = §cSchreibe keine inhaltslosen Nachrichten.
|
|||||||
|
|
||||||
CHAT_SERVERTEAM_SENDER = §e{0}
|
CHAT_SERVERTEAM_SENDER = §e{0}
|
||||||
CHAT_SERVERTEAM = §8» §f{2}
|
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_GLOBAL = §8» {7}{2}
|
||||||
CHAT_TEAM_SENDER = §e{0}
|
CHAT_TEAM_SENDER = §e{0}
|
||||||
CHAT_TEAM = §8» §f{2}
|
CHAT_TEAM = §8» §f{2}
|
||||||
@@ -558,6 +558,7 @@ CHAT_FIGHT_REFEREE = §8» §e{0}
|
|||||||
CHAT_FIGHT_TEAM = §8» §f{0}
|
CHAT_FIGHT_TEAM = §8» §f{0}
|
||||||
CHAT_ICON = {0}{1}
|
CHAT_ICON = {0}{1}
|
||||||
CHAT_HOVER_TEAM = §7Team: §e{0}\n§7Kürzel: §r{1}{2}
|
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_HOVER_LOCAL = {0}\n§7Server: §e{1}
|
||||||
CHAT_ICON_GLOBAL = 🌍
|
CHAT_ICON_GLOBAL = 🌍
|
||||||
CHAT_ICON_LOCAL = ⌂
|
CHAT_ICON_LOCAL = ⌂
|
||||||
|
|||||||
@@ -32,9 +32,11 @@ import de.steamwar.velocitycore.util.SteamwarPrefix;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.TextReplacementConfig;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
import net.kyori.adventure.text.event.HoverEvent;
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -42,6 +44,9 @@ public class ChatFormat {
|
|||||||
|
|
||||||
private static final Pattern MENTION = Pattern.compile("@(\\w{1,16})");
|
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<String> TEAM_PREFIX_FORMATS = Set.of("CHAT_GLOBAL");
|
||||||
|
|
||||||
private ChatFormat() {}
|
private ChatFormat() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,12 +57,15 @@ public class ChatFormat {
|
|||||||
SteamwarUser user = sender.user();
|
SteamwarUser user = sender.user();
|
||||||
UserPerm.Prefix prefix = user.prefix();
|
UserPerm.Prefix prefix = user.prefix();
|
||||||
|
|
||||||
String teamPrefix = "";
|
// The team prefix is its own component, so that clicking it suggests /team info
|
||||||
if (user.hasPerm(UserPerm.TEAM) && useSwPrefix(user)) {
|
Component teamPrefix = Component.empty();
|
||||||
teamPrefix = "§eS§8W ";
|
if (TEAM_PREFIX_FORMATS.contains(format)) {
|
||||||
} else if (user.getTeam() != 0) {
|
if (useSwPrefix(user)) {
|
||||||
Team team = Team.byId(user.getTeam());
|
teamPrefix = withTeamHover(receiver, user, Chatter.SERIALIZER.deserialize("§eS§8W")).append(Component.text(" "));
|
||||||
teamPrefix = "§" + team.getTeamColor() + team.getTeamKuerzel() + " ";
|
} 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";
|
String chatColorCode = user.hasPerm(UserPerm.TEAM) ? "§f" : "§7";
|
||||||
@@ -65,14 +73,14 @@ public class ChatFormat {
|
|||||||
user,
|
user,
|
||||||
msgReceiver == null ? receiver : msgReceiver,
|
msgReceiver == null ? receiver : msgReceiver,
|
||||||
highlightMentions(message, chatColorCode, receiver),
|
highlightMentions(message, chatColorCode, receiver),
|
||||||
teamPrefix,
|
"",
|
||||||
"",
|
"",
|
||||||
prefix == UserPerm.emptyPrefix ? "§f" : prefix.getColorCode(),
|
prefix == UserPerm.emptyPrefix ? "§f" : prefix.getColorCode(),
|
||||||
prefix.getChatPrefix().length() == 0 ? "§f" : prefix.getChatPrefix() + " ",
|
prefix.getChatPrefix().length() == 0 ? "§f" : prefix.getChatPrefix() + " ",
|
||||||
chatColorCode};
|
chatColorCode};
|
||||||
|
|
||||||
Component senderPart = withTeamHover(receiver, user, receiver.parse(new Message(format + "_SENDER", params)));
|
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);
|
Component team = Chatter.SERIALIZER.deserialize(coloredTeamName);
|
||||||
Team eventTeam = ChatManager.eventTeam(server, coloredTeamName);
|
Team eventTeam = ChatManager.eventTeam(server, coloredTeamName);
|
||||||
if (eventTeam != null) {
|
if (eventTeam != null) {
|
||||||
team = team.hoverEvent(HoverEvent.showText(teamHover(receiver, eventTeam)));
|
team = clickableTeam(receiver, eventTeam, team);
|
||||||
}
|
}
|
||||||
line.append(team).append(Component.text(" "));
|
line.append(team).append(Component.text(" "));
|
||||||
nameColor = coloredTeamName.length() >= 2 && coloredTeamName.charAt(0) == '§' ? coloredTeamName.substring(0, 2) : "";
|
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()))));
|
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) {
|
private static Component teamHover(Chatter receiver, Team team) {
|
||||||
return receiver.parse(new Message("CHAT_HOVER_TEAM", team.getTeamName(), "§" + team.getTeamColor(), team.getTeamKuerzel()));
|
return receiver.parse(new Message("CHAT_HOVER_TEAM", team.getTeamName(), "§" + team.getTeamColor(), team.getTeamKuerzel()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user