forked from SteamWar/SteamWar
Show team on hover for @name mentions
This commit is contained in:
@@ -129,7 +129,7 @@ public abstract class ChatChannel {
|
|||||||
for (Chatter receiver : receivers.values()) {
|
for (Chatter receiver : receivers.values()) {
|
||||||
if (!receiver.chatShown()) continue;
|
if (!receiver.chatShown()) continue;
|
||||||
|
|
||||||
Component msg = format(receiver, sender, coloredMessage);
|
Component msg = ChatFormat.withMentionHovers(receiver, format(receiver, sender, coloredMessage));
|
||||||
if (icon(receiver) != null) {
|
if (icon(receiver) != null) {
|
||||||
Component icon = iconComponent(receiver, ChatManager.getDefault(receiver) == this ? "§e" : "§7");
|
Component icon = iconComponent(receiver, ChatManager.getDefault(receiver) == this ? "§e" : "§7");
|
||||||
msg = Component.text().append(icon).append(Component.text(" ")).append(msg).build();
|
msg = Component.text().append(icon).append(Component.text(" ")).append(msg).build();
|
||||||
|
|||||||
@@ -31,13 +31,17 @@ import de.steamwar.velocitycore.network.NetworkSender;
|
|||||||
import de.steamwar.velocitycore.util.SteamwarPrefix;
|
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.event.HoverEvent;
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ChatFormat {
|
public class ChatFormat {
|
||||||
|
|
||||||
|
private static final Pattern MENTION = Pattern.compile("@(\\w{1,16})");
|
||||||
|
|
||||||
private ChatFormat() {}
|
private ChatFormat() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,6 +130,19 @@ public class ChatFormat {
|
|||||||
return SteamwarPrefix.usesSWPrefix(user);
|
return SteamwarPrefix.usesSWPrefix(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the team of every mentioned player ({@code @name}) on hover, like at the sender name.
|
||||||
|
*/
|
||||||
|
public static Component withMentionHovers(Chatter receiver, Component component) {
|
||||||
|
return component.replaceText(TextReplacementConfig.builder()
|
||||||
|
.match(MENTION)
|
||||||
|
.replacement((match, builder) -> {
|
||||||
|
SteamwarUser user = SteamwarUser.get(match.group(1));
|
||||||
|
return user == null ? builder : withTeamHover(receiver, user, builder.build());
|
||||||
|
})
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
public static String highlightMentions(String message, String returnColor, Chatter player) {
|
public static String highlightMentions(String message, String returnColor, Chatter player) {
|
||||||
if (!message.contains("@")) return message;
|
if (!message.contains("@")) return message;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user