diff options
| author | Sho Sakuma <me@m1sk9.dev> | 2026-08-02 19:45:33 +0900 |
|---|---|---|
| committer | Sho Sakuma <me@m1sk9.dev> | 2026-08-02 19:45:33 +0900 |
| commit | 7bcaaf9a305c2a8608a420c8f05521bd2de089dd (patch) | |
| tree | 8e7332ea740900284752a5f754c9d8286e073f67 | |
| parent | bc8010bc1b5401f11c80b565ba9a4de7d969a0a9 (diff) | |
| download | LunaticChat-7bcaaf9a305c2a8608a420c8f05521bd2de089dd.tar.gz LunaticChat-7bcaaf9a305c2a8608a420c8f05521bd2de089dd.tar.bz2 LunaticChat-7bcaaf9a305c2a8608a420c8f05521bd2de089dd.zip | |
refactor: fold the remaining small duplications
- MessageFormatter built the same prefix component in three functions.
- LanguageManager copied kaml's YamlNode into a private YamlValue tree
before flattening it, so the map case was written twice and the
list-of-maps case rendered a Kotlin data class toString into a player
facing string. It now folds YamlNode directly.
- StatusCommand inlined `if (enabled) "toggle.on" else "toggle.off"`,
which is the body of LanguageManager.getToggleText.
- The three chat formats each spelled out their own chain of
String.replace, with the valid placeholder names documented only in a
config.yml comment.
- ChannelContext carried a channelId that both construction sites filled
with channel.id; it is now derived, so the two cannot disagree.
- ChannelInfo and ChannelStatus each declared MAX_MEMBERS_DISPLAY = 10 and
built the same truncated member line, differing only in indent. A
divergence between the two constants would have been invisible.
Co-Authored-By: Claude <noreply@anthropic.com>
13 files changed, 106 insertions, 198 deletions
diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt index 02dc1d3..54b98e0 100644 --- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelContext.kt @@ -1,7 +1,12 @@ package dev.m1sk9.lunaticChat.engine.chat.channel +/** + * A player's active channel together with its member list. + */ data class ChannelContext( - val channelId: String, val channel: Channel, val members: List<ChannelMember>, -) +) { + /** Shorthand for the channel's id, which callers ask for far more often than the channel. */ + val channelId: String get() = channel.id +} diff --git a/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt b/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt index 4684432..de514b1 100644 --- a/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt +++ b/engine/src/test/kotlin/dev/m1sk9/lunaticChat/engine/chat/channel/ChannelDataClassesTest.kt @@ -114,7 +114,7 @@ class ChannelDataClassesTest { fun `ChannelContext should store all fields`() { val channel = Channel(id = "ch-1", name = "Test", ownerId = testOwnerId) val member = ChannelMember(channelId = "ch-1", playerId = testPlayerId, role = ChannelRole.MEMBER) - val context = ChannelContext(channelId = "ch-1", channel = channel, members = listOf(member)) + val context = ChannelContext(channel = channel, members = listOf(member)) assertEquals("ch-1", context.channelId) assertEquals(channel, context.channel) @@ -125,8 +125,8 @@ class ChannelDataClassesTest { @Test fun `ChannelContext copy should create independent instance`() { val channel = Channel(id = "ch-1", name = "Test", ownerId = testOwnerId) - val original = ChannelContext(channelId = "ch-1", channel = channel, members = emptyList()) - val copied = original.copy(channelId = "ch-2") + val original = ChannelContext(channel = channel, members = emptyList()) + val copied = original.copy(channel = channel.copy(id = "ch-2")) assertEquals("ch-2", copied.channelId) assertNotEquals(original.channelId, copied.channelId) diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt index 7305266..47780fb 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/channel/ChannelManager.kt @@ -446,7 +446,6 @@ class ChannelManager( } return ChannelContext( - channelId = channelId, channel = channel, members = members, ) @@ -480,7 +479,6 @@ class ChannelManager( saveToStorage() return ChannelContext( - channelId = channelId, channel = channel, members = members, ) diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/handler/ChannelMessageHandler.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/handler/ChannelMessageHandler.kt index 800e78a..985f321 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/handler/ChannelMessageHandler.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/handler/ChannelMessageHandler.kt @@ -8,6 +8,7 @@ import dev.m1sk9.lunaticChat.paper.common.playChannelReceiveNotification import dev.m1sk9.lunaticChat.paper.common.playMessageSendNotification import dev.m1sk9.lunaticChat.paper.config.LunaticChatConfiguration import dev.m1sk9.lunaticChat.paper.i18n.LanguageManager +import dev.m1sk9.lunaticChat.paper.i18n.withChatPlaceholders import dev.m1sk9.lunaticChat.paper.settings.PlayerSettingsManager import io.ktor.util.logging.Logger import net.kyori.adventure.text.Component @@ -98,10 +99,11 @@ class ChannelMessageHandler( ): Component { val format = configuration.messageFormat.channelMessageFormat val text = - format - .replace("{sender}", senderName) - .replace("{channel}", channelName) - .replace("{message}", message) + format.withChatPlaceholders( + "sender" to senderName, + "channel" to channelName, + "message" to message, + ) return Component.text(text) } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/handler/DirectMessageHandler.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/handler/DirectMessageHandler.kt index f92f01d..c3fc923 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/handler/DirectMessageHandler.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/chat/handler/DirectMessageHandler.kt @@ -7,6 +7,7 @@ import dev.m1sk9.lunaticChat.paper.config.LunaticChatConfiguration import dev.m1sk9.lunaticChat.paper.converter.RomanjiConverter import dev.m1sk9.lunaticChat.paper.converter.convertWithRomaji import dev.m1sk9.lunaticChat.paper.i18n.LanguageManager +import dev.m1sk9.lunaticChat.paper.i18n.withChatPlaceholders import dev.m1sk9.lunaticChat.paper.settings.PlayerSettingsManager import dev.m1sk9.lunaticChat.paper.velocity.RemotePlayerRegistry import net.kyori.adventure.text.Component @@ -236,10 +237,11 @@ class DirectMessageHandler( replyTo: String, ): Component { val text = - format - .replace("{sender}", senderName) - .replace("{recipient}", recipientName) - .replace("{message}", message) + format.withChatPlaceholders( + "sender" to senderName, + "recipient" to recipientName, + "message" to message, + ) return Component .text(text) diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/StatusCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/StatusCommand.kt index 526f1d3..62dc9cf 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/StatusCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/StatusCommand.kt @@ -164,7 +164,7 @@ class StatusCommand( label: String, enabled: Boolean, ): Component { - val toggleText = languageManager.getMessage(if (enabled) "toggle.on" else "toggle.off") + val toggleText = languageManager.getToggleText(enabled) val color = if (enabled) NamedTextColor.GREEN else NamedTextColor.GRAY return Component .text(" • ", NamedTextColor.GRAY) diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInfoCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInfoCommand.kt index 43d4515..01e7053 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInfoCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelInfoCommand.kt @@ -23,10 +23,6 @@ class ChannelInfoCommand( private val channelManager: ChannelManager, override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { - companion object { - private const val MAX_MEMBERS_DISPLAY = 10 - } - override val literal = "info" override val permissionNode = LunaticChatPermissionNode.ChannelInfo override val aliases = listOf("i") @@ -129,28 +125,7 @@ class ChannelInfoCommand( Bukkit.getOfflinePlayer(member.playerId).name } - val membersText = - if (memberNames.size > MAX_MEMBERS_DISPLAY) { - val displayNames = memberNames.take(MAX_MEMBERS_DISPLAY) - val message = - languageManager.getMessage( - "channel.info.membersOmitted", - mapOf("count" to memberNames.size.toString()), - ) - Component - .text(" ") - .append(Component.text(languageManager.getMessage("channel.info.members"), NamedTextColor.GRAY)) - .append(Component.text(": ", NamedTextColor.GRAY)) - .append(Component.text(displayNames.joinToString(", "), NamedTextColor.WHITE)) - .append(Component.text(" ... ", NamedTextColor.GRAY)) - .append(Component.text("($message)", NamedTextColor.YELLOW)) - } else { - Component - .text(" ") - .append(Component.text(languageManager.getMessage("channel.info.members"), NamedTextColor.GRAY)) - .append(Component.text(": ", NamedTextColor.GRAY)) - .append(Component.text(memberNames.joinToString(", "), NamedTextColor.WHITE)) - } + val membersText = memberListLine(memberNames, indent = " ", languageManager = languageManager) sender.sendMessage(membersText) diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelStatusCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelStatusCommand.kt index bd0f66f..78871b7 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelStatusCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelStatusCommand.kt @@ -28,10 +28,6 @@ class ChannelStatusCommand( private val membershipManager: ChannelMembershipManager, override val languageManager: LanguageManager, ) : LunaticSubCommand(plugin) { - companion object { - private const val MAX_MEMBERS_DISPLAY = 10 - } - override val literal = "status" override val permissionNode = LunaticChatPermissionNode.ChannelStatus override val aliases = listOf("st") @@ -104,36 +100,7 @@ class ChannelStatusCommand( playerName + roleText } - val membersText = - if (memberNames.size > MAX_MEMBERS_DISPLAY) { - val displayNames = memberNames.take(MAX_MEMBERS_DISPLAY) - val message = - languageManager.getMessage( - "channel.info.membersOmitted", - mapOf("count" to memberNames.size.toString()), - ) - Component - .text(" ") - .append( - Component.text( - languageManager.getMessage("channel.info.members"), - NamedTextColor.GRAY, - ), - ).append(Component.text(": ", NamedTextColor.GRAY)) - .append(Component.text(displayNames.joinToString(", "), NamedTextColor.WHITE)) - .append(Component.text(" ... ", NamedTextColor.GRAY)) - .append(Component.text("($message)", NamedTextColor.YELLOW)) - } else { - Component - .text(" ") - .append( - Component.text( - languageManager.getMessage("channel.info.members"), - NamedTextColor.GRAY, - ), - ).append(Component.text(": ", NamedTextColor.GRAY)) - .append(Component.text(memberNames.joinToString(", "), NamedTextColor.WHITE)) - } + val membersText = memberListLine(memberNames, indent = " ", languageManager = languageManager) sender.sendMessage(membersText) } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelSubCommand.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelSubCommand.kt index 0075970..b48c879 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelSubCommand.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/command/impl/lc/channel/ChannelSubCommand.kt @@ -6,11 +6,47 @@ import dev.m1sk9.lunaticChat.paper.LunaticChat import dev.m1sk9.lunaticChat.paper.chat.channel.ChannelManager import dev.m1sk9.lunaticChat.paper.chat.channel.ChannelMembershipManager import dev.m1sk9.lunaticChat.paper.command.core.LunaticSubCommand +import dev.m1sk9.lunaticChat.paper.i18n.LanguageManager +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.entity.Player import java.util.UUID +private const val MAX_MEMBERS_DISPLAY = 10 + +/** + * Renders a channel's member list on one line, truncated to [MAX_MEMBERS_DISPLAY] names with a + * count of what was left out. + * + * @param indent Leading whitespace, which differs by how deeply the caller nests the line + */ +internal fun memberListLine( + memberNames: List<String>, + indent: String, + languageManager: LanguageManager, +): Component { + val shown = memberNames.take(MAX_MEMBERS_DISPLAY) + val line = + Component + .text(indent) + .append(Component.text(languageManager.getMessage("channel.info.members"), NamedTextColor.GRAY)) + .append(Component.text(": ", NamedTextColor.GRAY)) + .append(Component.text(shown.joinToString(", "), NamedTextColor.WHITE)) + + if (memberNames.size <= MAX_MEMBERS_DISPLAY) return line + + val omitted = + languageManager.getMessage( + "channel.info.membersOmitted", + mapOf("count" to memberNames.size.toString()), + ) + return line + .append(Component.text(" ... ", NamedTextColor.GRAY)) + .append(Component.text("($omitted)", NamedTextColor.YELLOW)) +} + /** * A subcommand of `/lc channel`. * diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/ChatFormat.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/ChatFormat.kt new file mode 100644 index 0000000..3397ee1 --- /dev/null +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/ChatFormat.kt @@ -0,0 +1,10 @@ +package dev.m1sk9.lunaticChat.paper.i18n + +/** + * Substitutes `{name}` placeholders in one of the configurable chat formats. + * + * Which names a format accepts is documented alongside it in config.yml; going through this + * function keeps every format applying them the same way. + */ +fun String.withChatPlaceholders(vararg values: Pair<String, String>): String = + values.fold(this) { text, (name, value) -> text.replace("{$name}", value) } diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/LanguageManager.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/LanguageManager.kt index e13ebc7..dd702ba 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/LanguageManager.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/LanguageManager.kt @@ -1,27 +1,14 @@ package dev.m1sk9.lunaticChat.paper.i18n import com.charleskorn.kaml.Yaml +import com.charleskorn.kaml.YamlList +import com.charleskorn.kaml.YamlMap +import com.charleskorn.kaml.YamlNode +import com.charleskorn.kaml.YamlScalar import org.bukkit.plugin.java.JavaPlugin import java.util.logging.Logger /** - * Represents a value in a YAML structure. - */ -private sealed class YamlValue { - data class StringValue( - val value: String, - ) : YamlValue() - - data class MapValue( - val value: Map<String, YamlValue>, - ) : YamlValue() - - data class ListValue( - val value: List<YamlValue>, - ) : YamlValue() -} - -/** * Manages language files and provides message retrieval with string-based keys. * * This class handles: @@ -84,87 +71,34 @@ class LanguageManager( ?: throw IllegalStateException("Language file not found: $resourcePath") val yamlContent = stream.bufferedReader().use { it.readText() } - val yamlNode = Yaml.default.parseToYamlNode(yamlContent) + val root = Yaml.default.parseToYamlNode(yamlContent) + check(root is YamlMap) { "Root YAML node must be a map" } - val rootMap = yamlNodeToMap(yamlNode) - return flattenYaml(rootMap) + return buildMap { flattenInto(root, prefix = "", into = this) } } /** - * Converts a YamlNode to a type-safe YamlValue structure. - */ - private fun yamlNodeToMap(node: com.charleskorn.kaml.YamlNode): Map<String, YamlValue> = - when (node) { - is com.charleskorn.kaml.YamlMap -> { - val result = mutableMapOf<String, YamlValue>() - node.entries.forEach { entry -> - val key = entry.key.content - val value = yamlNodeToValue(entry.value) - result[key] = value - } - result - } - else -> throw IllegalStateException("Root YAML node must be a map") - } - - /** - * Converts a YamlNode to a type-safe YamlValue. - */ - private fun yamlNodeToValue(node: com.charleskorn.kaml.YamlNode): YamlValue = - when (node) { - is com.charleskorn.kaml.YamlMap -> { - val result = mutableMapOf<String, YamlValue>() - node.entries.forEach { entry -> - val key = entry.key.content - val value = yamlNodeToValue(entry.value) - result[key] = value - } - YamlValue.MapValue(result) - } - is com.charleskorn.kaml.YamlList -> { - YamlValue.ListValue(node.items.map { yamlNodeToValue(it) }) - } - is com.charleskorn.kaml.YamlScalar -> YamlValue.StringValue(node.content) - else -> YamlValue.StringValue(node.contentToString()) - } - - /** - * Flattens a nested map into dot-notation keys. + * Flattens a YAML tree into dot-notation keys. * Example: {"toggle": {"on": "有効"}} -> {"toggle.on": "有効"} */ - private fun flattenYaml( - map: Map<String, YamlValue>, - prefix: String = "", - ): Map<String, String> { - val result = mutableMapOf<String, String>() - - map.forEach { (key, value) -> - val fullKey = if (prefix.isEmpty()) key else "$prefix.$key" - - when (value) { - is YamlValue.MapValue -> { - result.putAll(flattenYaml(value.value, fullKey)) - } - is YamlValue.StringValue -> result[fullKey] = value.value - is YamlValue.ListValue -> { - // Lists are converted to comma-separated strings for simplicity - result[fullKey] = value.value.joinToString(", ") { yamlValueToString(it) } + private fun flattenInto( + node: YamlNode, + prefix: String, + into: MutableMap<String, String>, + ) { + when (node) { + is YamlMap -> + node.entries.forEach { (key, value) -> + val fullKey = if (prefix.isEmpty()) key.content else "$prefix.${key.content}" + flattenInto(value, fullKey, into) } - } + // Lists are converted to comma-separated strings for simplicity + is YamlList -> into[prefix] = node.items.joinToString(", ") { scalarText(it) } + else -> into[prefix] = scalarText(node) } - - return result } - /** - * Converts a YamlValue to String for flattening purposes. - */ - private fun yamlValueToString(value: YamlValue): String = - when (value) { - is YamlValue.StringValue -> value.value - is YamlValue.MapValue -> value.value.toString() - is YamlValue.ListValue -> value.value.toString() - } + private fun scalarText(node: YamlNode): String = (node as? YamlScalar)?.content ?: node.contentToString() /** * Retrieves a message for the given string key with optional placeholder substitution. diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/MessageFormatter.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/MessageFormatter.kt index d20c9f7..31aa0bb 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/MessageFormatter.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/i18n/MessageFormatter.kt @@ -30,21 +30,14 @@ object MessageFormatter { fun format( message: String, highlightPlaceholders: Boolean = true, - ): Component { - val prefix = - Component - .text("[LC] ") - .color(PREFIX_COLOR) - - val messageComponent = + ): Component = + prefixed( if (highlightPlaceholders) { formatWithPlaceholders(message, MESSAGE_COLOR) } else { Component.text(message).color(MESSAGE_COLOR) - } - - return prefix.append(messageComponent) - } + }, + ) /** * Formats an error message with the prefix and red text. @@ -52,16 +45,7 @@ object MessageFormatter { * @param message The error message text * @return A formatted Component with red text */ - fun formatError(message: String): Component { - val prefix = - Component - .text("[LC] ") - .color(PREFIX_COLOR) - - val messageComponent = formatWithPlaceholders(message, ERROR_COLOR) - - return prefix.append(messageComponent) - } + fun formatError(message: String): Component = prefixed(formatWithPlaceholders(message, ERROR_COLOR)) /** * Formats a success message with the prefix and green text. @@ -69,16 +53,9 @@ object MessageFormatter { * @param message The success message text * @return A formatted Component with green text */ - fun formatSuccess(message: String): Component { - val prefix = - Component - .text("[LC] ") - .color(PREFIX_COLOR) + fun formatSuccess(message: String): Component = prefixed(formatWithPlaceholders(message, SUCCESS_COLOR)) - val messageComponent = formatWithPlaceholders(message, SUCCESS_COLOR) - - return prefix.append(messageComponent) - } + private fun prefixed(message: Component): Component = Component.text("[LC] ").color(PREFIX_COLOR).append(message) /** * Parses a message and highlights placeholders in {braces} with yellow color. diff --git a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/velocity/CrossServerChatManager.kt b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/velocity/CrossServerChatManager.kt index 70ee6d4..2f2bde0 100644 --- a/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/velocity/CrossServerChatManager.kt +++ b/platform-paper/src/main/kotlin/dev/m1sk9/lunaticChat/paper/velocity/CrossServerChatManager.kt @@ -4,6 +4,7 @@ import dev.m1sk9.lunaticChat.engine.protocol.PluginMessage import dev.m1sk9.lunaticChat.engine.protocol.PluginMessageChannel import dev.m1sk9.lunaticChat.engine.protocol.PluginMessageCodec import dev.m1sk9.lunaticChat.paper.config.LunaticChatConfiguration +import dev.m1sk9.lunaticChat.paper.i18n.withChatPlaceholders import net.kyori.adventure.text.Component import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import org.bukkit.plugin.Plugin @@ -126,10 +127,11 @@ class CrossServerChatManager( private fun formatCrossServerMessage(message: PluginMessage.GlobalChatMessage): Component { val format = configuration.messageFormat.crossServerGlobalChatFormat val formattedText = - format - .replace("{server}", message.serverName) - .replace("{sender}", message.playerName) - .replace("{message}", message.message) + format.withChatPlaceholders( + "server" to message.serverName, + "sender" to message.playerName, + "message" to message.message, + ) return LegacyComponentSerializer.legacySection().deserialize(formattedText) } |
