diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt index 9ec9c3b..09347fa 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt @@ -13,6 +13,7 @@ import com.mineinabyss.chatty.components.ChannelType import com.mineinabyss.chatty.components.chattyNickname import com.mineinabyss.chatty.placeholders.chattyPlaceholderTags import com.mineinabyss.chatty.tags.ChattyTags +import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.idofront.messaging.warn import com.mineinabyss.idofront.textcomponents.miniMsg import com.mineinabyss.idofront.textcomponents.serialize @@ -125,11 +126,16 @@ fun Player.sendFormattedMessage(vararg message: String, optionalPlayer: Player? translatePlaceholders((optionalPlayer ?: this), message.joinToString(" ")).miniMsg((optionalPlayer ?: this).buildTagResolver(true)) ) +fun appendChannelFormat(message: Component, player: Player): Component { + val channelData = player.toGearyOrNull()?.get() ?: return message + val channel = channelData.withChannelVerified().channel ?: return message + return appendChannelFormat(message, player, channel) +} fun appendChannelFormat(message: Component, player: Player, channel: ChattyChannel): Component { val parsedFormat = translatePlaceholders(player, channel.format).miniMsg(player.buildTagResolver(true)) val parsedMessage = Component.empty().color(channel.messageColor).append(message) - return parsedFormat.compact().append(parsedMessage) + return Component.textOfChildren(parsedFormat, parsedMessage) } fun Component.hoverEventShowText(text: Component) = this.hoverEvent(HoverEventSource.unbox(HoverEvent.showText(text))) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt index 7c25e31..6c3e873 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt @@ -50,7 +50,10 @@ class ChatListener : Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) fun AsyncChatDecorateEvent.onChatPreview() { - player()?.let { result(result().parseTags(it, false)) } + player()?.let { player -> + result(result().parseTags(player, false)) + result(appendChannelFormat(result(), player)) + } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -59,6 +62,7 @@ class ChatListener : Listener { val channelData = ogChannelData.withChannelVerified() val channelId = channelData.channelId val channel = channelData.channel ?: return + val baseMessage = message().children().last() if (viewers().isNotEmpty()) viewers().clear() viewers() += channel.getAudience(player) @@ -67,7 +71,7 @@ class ChatListener : Listener { if (chattyEvent.callEvent()) message(chattyEvent.message) else viewers().clear() - val simpleMessage = Component.textOfChildren(player.name().style(Style.style(TextDecoration.ITALIC)), Component.text(": "), message()) + val simpleMessage = Component.textOfChildren(player.name().style(Style.style(TextDecoration.ITALIC)), Component.text(": "), baseMessage) if (channel.logToConsole) Bukkit.getConsoleSender().sendMessage(simpleMessage) handleProxyMessage(player, channelId, channel, message(), simpleMessage) @@ -80,7 +84,6 @@ class ChatListener : Listener { var finalMessage = message() finalMessage = handleChatFilters(finalMessage, player, receiver) ?: return@forEach finalMessage = formatPlayerPingMessage(player, pingedPlayer, receiver, finalMessage) - finalMessage = appendChannelFormat(finalMessage, player, channel) finalMessage = formatModerationMessage( channel.messageDeletion, finalMessage, @@ -102,7 +105,6 @@ class ChatListener : Listener { var finalMessage = message finalMessage = handleChatFilters(finalMessage, player, audience as? Player) ?: return@renderer Component.empty() finalMessage = formatPlayerPingMessage(source, pingedPlayer, audience, finalMessage) - finalMessage = appendChannelFormat(finalMessage, player, channel) finalMessage = formatModerationMessage( channel.messageDeletion, finalMessage,