Clean up simpleclans_clan_color_tag expansion

This commit is contained in:
SKBotNL committed 2026-05-08 11:55:59 +02:00
1 parent 22dd63f456
commit d33dd27274
5 files changed
+18 -46

No files matched your search

+8 -8
View File
@@ -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("<simpleclans_clan_color_tag>", event.player)
val unionPlainTag = UtilitiesOG.stripFormatting(unionTag)
if (unionPlainTag.isNotEmpty() && unionPlainTag != "None") {
nameString = "&8[$unionTag&8] $nameString"
}
val nameComponent = UtilitiesOG.trueogColorize(legacyToMm(nameString))
@@ -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)
@@ -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")
@@ -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("<simpleclans_clan_color_tag>", player)
val unionPlainTag = UtilitiesOG.stripFormatting(unionTag)
if (unionPlainTag.isNotEmpty() && unionPlainTag != "None") {
playerString = "&8[$unionTag&8] $playerString"
}
val playerComponent =
UtilitiesOG.trueogColorize(
@@ -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("<simpleclans_clan_color_tag>", 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("<simpleclans_clan_color_tag>", resolver)
return captured
}
val mentionRegex = Regex("@([A-Za-z0-9_]{3,16})")
fun dingForMentions(dontDingFor: UUID, component: Component) {