Skip to content

Commit

Permalink
refactor: move channel-format into AsyncChatDecorateEvent & fix cross…
Browse files Browse the repository at this point in the history
…-server
  • Loading branch information
Boy0000 committed Jan 27, 2024
1 parent 2df8ca6 commit 608a7f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions chatty-paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ dependencies {

}

tasks {
shadowJar {
archiveFile.get().asFile.copyTo(file("D:\\Server\\t\\paper2\\plugins\\Chatty.jar"), true)
}
}

configurations {
findByName("runtimeClasspath")?.apply {
exclude(group = "org.jetbrains.kotlin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ChannelData>() ?: 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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 608a7f5

Please sign in to comment.