diff --git a/src/main/java/cn/dreeam/surf/config/Config.java b/src/main/java/cn/dreeam/surf/config/Config.java index 1004a1f..5f5c13a 100644 --- a/src/main/java/cn/dreeam/surf/config/Config.java +++ b/src/main/java/cn/dreeam/surf/config/Config.java @@ -22,7 +22,7 @@ public class Config { public static String limitOffhandSwapMessage; // Misc / Connection / Nether - public static boolean connectionMessageEnabled, connectionFirstJoinEnabled, connectionPreventKickEnabled, netherEnabled, netherTopBottomDoDamage; + public static boolean connectionMessageEnabled, connectionMessageUseDisplayName, connectionFirstJoinEnabled, connectionPreventKickEnabled, netherEnabled, netherTopBottomDoDamage; public static int netherTopLayer, netherBottomLayer; public static String connectionPlayerJoin, connectionPlayerLeave, connectionFirstJoinMessage, netherTopMessage, netherBottomMessage; public static List connectionKickReasons; @@ -94,6 +94,8 @@ public static void initConfig() { connectionMessageEnabled = Surf.configManager().getBoolean("connection-meesage.enabled", false, """ These are the connection messages for when a player joins / leaves Use & for colours and %player% as a placeholder for the players name"""); + connectionMessageUseDisplayName = Surf.configManager().getBoolean("connection-meesage.use-display-name", true, """ + Whether use display name in connection messages."""); connectionPlayerJoin = Surf.configManager().getString("connection-meesage.player-join", "&7[&a+&7] &8%player%"); connectionPlayerLeave = Surf.configManager().getString("connection-meesage.player-leave", "&7[&c-&7] &8%player%"); diff --git a/src/main/java/cn/dreeam/surf/modules/misc/ConnectionEvent.java b/src/main/java/cn/dreeam/surf/modules/misc/ConnectionEvent.java index b3b4c68..364f68c 100644 --- a/src/main/java/cn/dreeam/surf/modules/misc/ConnectionEvent.java +++ b/src/main/java/cn/dreeam/surf/modules/misc/ConnectionEvent.java @@ -4,6 +4,7 @@ import cn.dreeam.surf.config.Config; import cn.dreeam.surf.util.Util; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -50,8 +51,16 @@ public void onKick(PlayerKickEvent event) { } private Component getConnectionMessage(Player player, String message) { - message = message.replace("%player%", player.getName()); + Component connecntionComponent; - return LegacyComponentSerializer.legacyAmpersand().deserialize(message); + if (Config.connectionMessageUseDisplayName && !player.displayName().equals(Component.empty())) { + connecntionComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(message) + .replaceText(TextReplacementConfig.builder().matchLiteral("%player%").replacement(player.displayName()).build()); + } else { + message = message.replace("%player%", player.getName()); + connecntionComponent = LegacyComponentSerializer.legacyAmpersand().deserialize(message); + } + + return connecntionComponent; } } \ No newline at end of file