Skip to content

Commit

Permalink
feat: add ChattyPlayerChatEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Dec 29, 2023
1 parent 38b90b1 commit 6704dab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mineinabyss.chatty.events

import com.mineinabyss.chatty.ChattyChannel
import io.papermc.paper.event.player.AbstractChatEvent
import net.kyori.adventure.audience.Audience
import net.kyori.adventure.text.Component
import org.bukkit.entity.Player
import org.bukkit.event.Event
import org.bukkit.event.HandlerList
import org.bukkit.event.player.PlayerEvent

class ChattyPlayerChatEvent(player: Player, val channel: ChattyChannel, val message: Component, val viewers: MutableSet<Audience>) : PlayerEvent(player, true) {
companion object {
@JvmStatic
val handlerList = HandlerList()
}

override fun getHandlers(): HandlerList = handlerList
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.mineinabyss.chatty.chatty
import com.mineinabyss.chatty.chattyProxyChannel
import com.mineinabyss.chatty.components.ChannelData
import com.mineinabyss.chatty.components.CommandSpy
import com.mineinabyss.chatty.components.chattyNickname
import com.mineinabyss.chatty.events.ChattyPlayerChatEvent
import com.mineinabyss.chatty.helpers.*
import com.mineinabyss.geary.datatypes.family.family
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
Expand All @@ -16,7 +16,6 @@ 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.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.Style
import net.kyori.adventure.text.format.TextDecoration
import net.kyori.adventure.text.minimessage.MiniMessage
Expand Down Expand Up @@ -65,6 +64,10 @@ class ChatListener : Listener {
if (viewers().isNotEmpty()) viewers().clear()
viewers() += channel.getAudience(player)

val chattyEvent = ChattyPlayerChatEvent(player, channel, message(), viewers())
if (chattyEvent.callEvent()) message(chattyEvent.message)
else viewers().clear()

if (channel.proxy) {
//Append channel to give proxy info on what channel the message is from
val proxyMessage = (("${player.name}$ZERO_WIDTH$channelId$ZERO_WIDTH" +
Expand Down

0 comments on commit 6704dab

Please sign in to comment.