#43: add server placeholder support for velocity

This commit is contained in:
2026-08-07 12:56:45 +02:00
parent 89e26a8958
commit 97676fc4c8
4 changed files with 23 additions and 25 deletions
@@ -7,7 +7,7 @@ import java.util.Set;
import java.util.UUID;
import me.oskar3123.staffchat.bungee.BungeeMain;
import me.oskar3123.staffchat.bungee.event.BungeeStaffChatEvent;
import me.oskar3123.staffchat.bungee.util.BungeeFormatUtils;
import me.oskar3123.staffchat.util.FormatUtils;
import me.oskar3123.staffchat.util.Permissions;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
@@ -66,7 +66,7 @@ public class BungeeChatListener implements Listener {
message = chatEvent.getMessage();
String appliedFormat =
BungeeFormatUtils.replacePlaceholders(
FormatUtils.replacePlaceholders(
format,
s -> ChatColor.translateAlternateColorCodes('&', s),
() ->
@@ -1,22 +0,0 @@
package me.oskar3123.staffchat.bungee.util;
import java.util.function.Function;
import java.util.function.Supplier;
import me.oskar3123.staffchat.util.FormatUtils;
import me.oskar3123.staffchat.util.StringUtils;
public class BungeeFormatUtils {
private BungeeFormatUtils() {}
public static String replacePlaceholders(
String string,
Function<String, String> colorize,
Supplier<String> serverSupplier,
Supplier<String> nameSupplier,
String message) {
string =
string.replaceAll("\\{SERVER}", StringUtils.sanitize(colorize.apply(serverSupplier.get())));
return FormatUtils.replacePlaceholders(string, colorize, nameSupplier, message);
}
}
@@ -7,6 +7,17 @@ public class FormatUtils {
private FormatUtils() {}
public static String replacePlaceholders(
String string,
Function<String, String> colorize,
Supplier<String> serverSupplier,
Supplier<String> nameSupplier,
String message) {
string =
string.replaceAll("\\{SERVER}", StringUtils.sanitize(colorize.apply(serverSupplier.get())));
return replacePlaceholders(string, colorize, nameSupplier, message);
}
public static String replacePlaceholders(
String string,
Function<String, String> colorize,
@@ -61,7 +61,16 @@ public class VelocityStaffChatHandler {
private void broadcastStaffMessage(Player player, String format, String message) {
String formattedMessage =
FormatUtils.replacePlaceholders(format, Function.identity(), player::getUsername, message);
FormatUtils.replacePlaceholders(
format,
Function.identity(),
() ->
player
.getCurrentServer()
.map(connection -> connection.getServerInfo().getName())
.orElse(""),
player::getUsername,
message);
TextComponent component =
LegacyComponentSerializer.legacyAmpersand().deserialize(formattedMessage);