Skip to content

Commit

Permalink
refactor: move final formatting logic into shared handleFinalMessage …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
Boy0000 committed Jan 21, 2024
1 parent be770ea commit 07564fe
Showing 1 changed file with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.mineinabyss.idofront.textcomponents.serialize
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent
import io.papermc.paper.event.player.AsyncChatDecorateEvent
import io.papermc.paper.event.player.AsyncChatEvent
import net.kyori.adventure.chat.SignedMessage
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.Style
import net.kyori.adventure.text.format.TextDecoration
Expand Down Expand Up @@ -80,52 +81,29 @@ class ChatListener : Listener {
chatty.config.chat.disableChatSigning -> {
playerViewers.forEach { audience ->
val audienceTranslation = audience.toGearyOrNull()?.get<ChattyTranslation>()
var finalMessage = message()
finalMessage = handleMessageTranslation(player, channel, playerTranslation, audienceTranslation, finalMessage, signedMessage())
finalMessage = handleChatFilters(finalMessage, player, audience) ?: return@forEach
finalMessage = formatPlayerPingMessage(player, pingedPlayer, audience, finalMessage)
finalMessage = appendChannelFormat(finalMessage, player, channel)
finalMessage = formatModerationMessage(
channel.messageDeletion,
finalMessage,
simpleMessage,
signedMessage(),
audience,
player,
playerViewers
)

audience.sendMessage(finalMessage)
audience.sendMessage(handleFinalMessage(player, channel, message(), signedMessage(), simpleMessage, audience, playerTranslation, audienceTranslation, pingedPlayer, playerViewers))
}

viewers().clear()
//isCancelled = true
}

else -> renderer { source, _, message, audience ->
if (audience !is Player) return@renderer Component.empty()

val audienceTranslation = audience.toGearyOrNull()?.get<ChattyTranslation>()
var finalMessage = message
finalMessage = handleMessageTranslation(player, channel, playerTranslation, audienceTranslation, finalMessage, signedMessage())
finalMessage = handleChatFilters(finalMessage, player, audience) ?: return@renderer Component.empty()
finalMessage = formatPlayerPingMessage(source, pingedPlayer, audience, finalMessage)
finalMessage = appendChannelFormat(finalMessage, player, channel)
finalMessage = formatModerationMessage(
channel.messageDeletion,
finalMessage,
simpleMessage,
signedMessage(),
audience,
source,
playerViewers
)

return@renderer finalMessage
return@renderer handleFinalMessage(source, channel, message, signedMessage(), simpleMessage, audience, playerTranslation, audienceTranslation, pingedPlayer, playerViewers)
}
}
}

private fun handleFinalMessage(source: Player, channel: ChattyChannel, message: Component, signedMessage: SignedMessage, simpleMessage: Component, audience: Player, playerTranslation: ChattyTranslation?, audienceTranslation: ChattyTranslation?, pingedPlayer: Player?, playerViewers: Set<Player>) : Component {
return message
.let { handleMessageTranslation(source, channel, playerTranslation, audienceTranslation, it, signedMessage) }
.let { handleChatFilters(it, source, audience) }
.let { formatPlayerPingMessage(source, pingedPlayer, audience, message) }
.let { appendChannelFormat(it, source, channel) }
.let { formatModerationMessage(channel.messageDeletion, it, simpleMessage, signedMessage, audience, source, playerViewers) }
}

private fun handleProxyMessage(player: Player, channelId: String, channel: ChattyChannel, message: Component, simpleMessage: Component) {
if (!channel.proxy) return
val proxyMessage = Component.textOfChildren(player.name(), Component.text(channelId), message, simpleMessage)
Expand Down

0 comments on commit 07564fe

Please sign in to comment.