From d33dd27274885b52e4dc0edf978376a2811b112d Mon Sep 17 00:00:00 2001 From: Sven Date: Fri, 8 May 2026 11:55:59 +0200 Subject: [PATCH] Clean up simpleclans_clan_color_tag expansion --- src/main/kotlin/nl/skbotnl/chatog/Events.kt | 16 ++++----- .../skbotnl/chatog/chatsystem/ChatSystem.kt | 2 +- .../skbotnl/chatog/discord/DiscordBridge.kt | 2 +- .../translation/command/TranslateMessage.kt | 8 ++--- .../kotlin/nl/skbotnl/chatog/util/ChatUtil.kt | 36 +++---------------- 5 files changed, 18 insertions(+), 46 deletions(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/Events.kt b/src/main/kotlin/nl/skbotnl/chatog/Events.kt index 3b223c5..158ff0e 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Events.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Events.kt @@ -42,7 +42,7 @@ internal class Events : Listener { return } - val playerPartString = ChatUtil.getDiscordPlayerPartString(event.player) + val playerPartString = ChatUtil.getPlayerPartString(event.player, includeSuffix = true) scope.launch { discordBridgeLock.read { @@ -66,7 +66,7 @@ internal class Events : Listener { return } - val playerPartString = ChatUtil.getDiscordPlayerPartString(event.player) + val playerPartString = ChatUtil.getPlayerPartString(event.player, includeSuffix = true) scope.launch { discordBridgeLock.read { @@ -90,7 +90,7 @@ internal class Events : Listener { return } - val playerPartString = ChatUtil.getDiscordPlayerPartString(event.player) + val playerPartString = ChatUtil.getPlayerPartString(event.player, includeSuffix = true) val reason = PlainTextComponentSerializer.plainText().serialize(event.reason()) @@ -116,7 +116,7 @@ internal class Events : Listener { return } - val playerPartString = ChatUtil.getDiscordPlayerPartString(event.player) + val playerPartString = ChatUtil.getPlayerPartString(event.player, includeSuffix = true) val advancementTitleKey = event.advancement.display?.title() ?: return val advancementTitle = PlainTextComponentSerializer.plainText().serialize(advancementTitleKey) @@ -190,10 +190,10 @@ internal class Events : Listener { var nameString = "${PlayerUtils.getPrefix(event.player.uniqueId)}${event.player.name}" - val unionColorTag = ChatUtil.fetchUnionColorTag(event.player) - val unionPlain = ChatUtil.stripFormatting(unionColorTag) - if (unionPlain.isNotEmpty() && unionPlain != "None") { - nameString = "&8[$unionColorTag&8] $nameString" + val unionTag = UtilitiesOG.trueogExpand("", event.player) + val unionPlainTag = UtilitiesOG.stripFormatting(unionTag) + if (unionPlainTag.isNotEmpty() && unionPlainTag != "None") { + nameString = "&8[$unionTag&8] $nameString" } val nameComponent = UtilitiesOG.trueogColorize(legacyToMm(nameString)) diff --git a/src/main/kotlin/nl/skbotnl/chatog/chatsystem/ChatSystem.kt b/src/main/kotlin/nl/skbotnl/chatog/chatsystem/ChatSystem.kt index 3336934..e0c990b 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/chatsystem/ChatSystem.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/chatsystem/ChatSystem.kt @@ -24,7 +24,7 @@ internal abstract class ChatSystem { playerPartString = listOfNotNull(prefix, playerPartString).joinToString(" | ") val discordPlayerPartString = - listOfNotNull(prefix, ChatUtil.getDiscordPlayerPartString(player)).joinToString(" | ") + listOfNotNull(prefix, ChatUtil.getPlayerPartString(player, includeSuffix = true)).joinToString(" | ") sendDiscordMessage(text, discordPlayerPartString, player.uniqueId) diff --git a/src/main/kotlin/nl/skbotnl/chatog/discord/DiscordBridge.kt b/src/main/kotlin/nl/skbotnl/chatog/discord/DiscordBridge.kt index 701cb8a..34e2848 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/discord/DiscordBridge.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/discord/DiscordBridge.kt @@ -393,7 +393,7 @@ internal class DiscordBridge private constructor() { suspend fun sendMessage(message: String, player: Player) { val webhookMessage = WebhookMessageBuilder() - .setUsername(UtilitiesOG.stripFormatting(ChatUtil.getDiscordPlayerPartString(player))) + .setUsername(UtilitiesOG.stripFormatting(ChatUtil.getPlayerPartString(player, includeSuffix = true))) .setContent(UtilitiesOG.stripFormatting(ChatUtil.stripGroupMentions(ChatUtil.convertMentions(message)))) .setAvatarUrl("https://minotar.net/helm/${player.uniqueId}.png") diff --git a/src/main/kotlin/nl/skbotnl/chatog/translation/command/TranslateMessage.kt b/src/main/kotlin/nl/skbotnl/chatog/translation/command/TranslateMessage.kt index 4ce017c..ca6dab5 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/translation/command/TranslateMessage.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/translation/command/TranslateMessage.kt @@ -142,10 +142,10 @@ internal class TranslateMessage : CommandExecutor { "${PlayerUtils.getPrefix(sentChatMessage.player.uniqueId)}${sentChatMessage.player.name}${ PlayerUtils.getSuffix(sentChatMessage.player.uniqueId) }" - val unionColorTag = ChatUtil.fetchUnionColorTag(sentMessage.player) - val unionPlain = ChatUtil.stripFormatting(unionColorTag) - if (unionPlain.isNotEmpty() && unionPlain != "None") { - playerString = "&8[$unionColorTag&8] $playerString" + val unionTag = UtilitiesOG.trueogExpand("", player) + val unionPlainTag = UtilitiesOG.stripFormatting(unionTag) + if (unionPlainTag.isNotEmpty() && unionPlainTag != "None") { + playerString = "&8[$unionTag&8] $playerString" } val playerComponent = UtilitiesOG.trueogColorize( diff --git a/src/main/kotlin/nl/skbotnl/chatog/util/ChatUtil.kt b/src/main/kotlin/nl/skbotnl/chatog/util/ChatUtil.kt index c2188df..838260f 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/util/ChatUtil.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/util/ChatUtil.kt @@ -1,7 +1,6 @@ package nl.skbotnl.chatog.util import dev.minn.jda.ktx.coroutines.await -import io.github.miniplaceholders.api.MiniPlaceholders import java.util.* import kotlin.concurrent.read import net.kyori.adventure.text.Component @@ -10,7 +9,6 @@ import net.kyori.adventure.text.event.HoverEvent import net.kyori.adventure.text.format.TextColor import net.kyori.adventure.text.minimessage.Context import net.kyori.adventure.text.minimessage.MiniMessage -import net.kyori.adventure.text.minimessage.tag.PreProcess import net.kyori.adventure.text.minimessage.tag.Tag import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver @@ -31,41 +29,15 @@ internal object ChatUtil { var playerPart = "${PlayerUtils.getPrefix(player.uniqueId)}${player.name}${if (includeSuffix) PlayerUtils.getSuffix(player.uniqueId) else ""}" - val unionColorTag = fetchUnionColorTag(player) - val unionPlain = stripFormatting(unionColorTag) - if (unionPlain.isNotEmpty() && unionPlain != "None") { - playerPart = legacyToMm("&8[$unionColorTag&8] ") + playerPart + val unionTag = UtilitiesOG.trueogExpand("", player) + val unionPlainTag = UtilitiesOG.stripFormatting(unionTag) + if (unionPlainTag.isNotEmpty() && unionPlainTag != "None") { + playerPart = legacyToMm("&8[$unionTag&8] ") + playerPart } return playerPart } - fun getDiscordPlayerPartString(player: Player): String { - return getPlayerPartString(player, includeSuffix = true) - } - - fun fetchUnionColorTag(player: Player): String { - var captured = "" - val original = MiniPlaceholders.getAudiencePlaceholders(player) - val capturingResolver = - object : TagResolver { - override fun resolve(name: String, arguments: ArgumentQueue, ctx: Context): Tag? { - val tag = original.resolve(name, arguments, ctx) ?: return null - if (tag is PreProcess) { - captured = tag.value().replace('ยง', '&') - return Tag.preProcessParsed("") - } - return tag - } - - override fun has(name: String): Boolean = original.has(name) - } - val resolver = - TagResolver.builder().resolver(MiniPlaceholders.getGlobalPlaceholders()).resolver(capturingResolver).build() - MiniMessage.miniMessage().deserialize("", resolver) - return captured - } - val mentionRegex = Regex("@([A-Za-z0-9_]{3,16})") fun dingForMentions(dontDingFor: UUID, component: Component) {