diff --git a/src/main/kotlin/io/github/quiltservertools/blockbotdiscord/config/ChatRelaySpec.kt b/src/main/kotlin/io/github/quiltservertools/blockbotdiscord/config/ChatRelaySpec.kt index 13e56cb..4ffb984 100644 --- a/src/main/kotlin/io/github/quiltservertools/blockbotdiscord/config/ChatRelaySpec.kt +++ b/src/main/kotlin/io/github/quiltservertools/blockbotdiscord/config/ChatRelaySpec.kt @@ -1,5 +1,6 @@ package io.github.quiltservertools.blockbotdiscord.config +import com.google.gson.JsonParser import com.mojang.authlib.GameProfile import com.uchuhimo.konf.Config import com.uchuhimo.konf.ConfigSpec @@ -11,6 +12,7 @@ import io.github.quiltservertools.blockbotapi.sender.PlayerMessageSender import io.github.quiltservertools.blockbotdiscord.utility.getTextures import io.github.quiltservertools.blockbotdiscord.utility.literal import io.github.quiltservertools.blockbotdiscord.utility.summary +import net.fabricmc.loader.api.FabricLoader import net.minecraft.advancement.Advancement import net.minecraft.server.MinecraftServer import net.minecraft.server.network.ServerPlayerEntity @@ -18,6 +20,7 @@ import net.minecraft.text.LiteralText import net.minecraft.text.MutableText import net.minecraft.text.Text import net.minecraft.util.Formatting +import java.util.* object ChatRelaySpec : ConfigSpec() { val allowMentions by required() @@ -55,9 +58,12 @@ object ChatRelaySpec : ConfigSpec() { val webhookName by required() val webhookAvatar by required() val playerAvatarUrl by required() + val tailorAvatarUrl by required() } } +val usingFabricTailor: Boolean = FabricLoader.getInstance().isModLoaded("fabrictailor") + fun Config.formatDiscordMessage(sender: MessageSender, message: String): String = formatDiscordRelayMessage(sender, message, config[ChatRelaySpec.DiscordMessageFormatSpec.messageFormat]) @@ -185,13 +191,30 @@ fun Config.getReplyMsg( ), server ) -fun Config.getWebhookChatRelayAvatar(gameProfile: GameProfile): String = - PlaceholderAPI.parsePredefinedText( +fun Config.getWebhookChatRelayAvatar(gameProfile: GameProfile): String { + val textures = gameProfile.getTextures() + + if (usingFabricTailor && textures != null) { + // FabricTailor is active, use its textures + val decode = JsonParser.parseString(String(Base64.getDecoder().decode(textures))) + val skinUrl = decode.asJsonObject.get("textures").asJsonObject.get("SKIN").asJsonObject.get("url").asString + + return PlaceholderAPI.parsePredefinedText( + this[ChatRelaySpec.WebhookSpec.tailorAvatarUrl].literal(), + PlaceholderAPI.ALT_PLACEHOLDER_PATTERN_CUSTOM, + mapOf( + "texture" to skinUrl.split("/").last().literal() + ) + ).string + } + + return PlaceholderAPI.parsePredefinedText( this[ChatRelaySpec.WebhookSpec.playerAvatarUrl].literal(), PlaceholderAPI.ALT_PLACEHOLDER_PATTERN_CUSTOM, mapOf( "uuid" to gameProfile.id.toString().literal(), "username" to gameProfile.name.literal(), - "texture" to (gameProfile.getTextures()?.literal() ?: LiteralText("")) + "texture" to (textures?.literal() ?: LiteralText("")) ) ).string +}