Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f637ec4c9a | ||
|
|
97676fc4c8 |
@@ -7,7 +7,7 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import me.oskar3123.staffchat.bungee.BungeeMain;
|
import me.oskar3123.staffchat.bungee.BungeeMain;
|
||||||
import me.oskar3123.staffchat.bungee.event.BungeeStaffChatEvent;
|
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 me.oskar3123.staffchat.util.Permissions;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
@@ -66,7 +66,7 @@ public class BungeeChatListener implements Listener {
|
|||||||
message = chatEvent.getMessage();
|
message = chatEvent.getMessage();
|
||||||
|
|
||||||
String appliedFormat =
|
String appliedFormat =
|
||||||
BungeeFormatUtils.replacePlaceholders(
|
FormatUtils.replacePlaceholders(
|
||||||
format,
|
format,
|
||||||
s -> ChatColor.translateAlternateColorCodes('&', s),
|
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() {}
|
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(
|
public static String replacePlaceholders(
|
||||||
String string,
|
String string,
|
||||||
Function<String, String> colorize,
|
Function<String, String> colorize,
|
||||||
|
|||||||
+10
-1
@@ -61,7 +61,16 @@ public class VelocityStaffChatHandler {
|
|||||||
|
|
||||||
private void broadcastStaffMessage(Player player, String format, String message) {
|
private void broadcastStaffMessage(Player player, String format, String message) {
|
||||||
String formattedMessage =
|
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 =
|
TextComponent component =
|
||||||
LegacyComponentSerializer.legacyAmpersand().deserialize(formattedMessage);
|
LegacyComponentSerializer.legacyAmpersand().deserialize(formattedMessage);
|
||||||
|
|||||||
Reference in New Issue
Block a user