Skip to content

Commit

Permalink
Reduce coroutine scope for player chat event
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeberrex committed Jul 19, 2024
1 parent 3ce26c6 commit 67e3d54
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ChatListener : Listener {
}

@EventHandler
fun onPlayerChat(event: AsyncPlayerChatEvent) = runBlocking {
fun onPlayerChat(event: AsyncPlayerChatEvent) {
val player = event.player
val context = PlayerManager.getPlayer(player.uniqueId)!!

Expand All @@ -140,7 +140,7 @@ class ChatListener : Listener {
?: throw RuntimeException("No appeal link set in config")
if (activeMute.action.isPermanent()) player.sendMessage("${GRAY}You are muted for ${RED}${activeMute.reason.name}${GRAY}. $RED${activeMute.reason.message} ${GRAY}You may appeal at ${AQUA}$appealLink")
else player.sendMessage("${GRAY}You are muted for ${RED}${activeMute.reason.name} ${GRAY}until ${WHITE}${activeMute.expiresAt} (${activeMute.expiresAt.getRelativeTime()})${GRAY}. $RED${activeMute.reason.message} ${GRAY}You may appeal at ${AQUA}$appealLink")
return@runBlocking
return
}
val chatChannel =
if (Integration.isVanished(context.player) && context.player.hasPermission(Permissions.ADMINCHAT)) SettingValue.CHAT_ADMIN
Expand All @@ -150,13 +150,14 @@ class ChatListener : Listener {
if (chatChannel == SettingValue.CHAT_GLOBAL && !isChatEnabled && !player.hasPermission("mars.chat.mute.bypass")) {
player.sendMessage("${RED}Global chat is currently disabled.")
event.isCancelled = true
return@runBlocking
return
}

when (chatChannel) {
SettingValue.CHAT_ADMIN -> sendAdminChat(match, context.getPrefix() ?: "", player.name, event.message, null)
SettingValue.CHAT_TEAM -> sendTeamChat(context.matchPlayer.party, context, event.message)
else -> sendGlobalChat(match, context, event.message)
runBlocking {
when (chatChannel) {
SettingValue.CHAT_ADMIN -> sendAdminChat(match, context.getPrefix() ?: "", player.name, event.message, null)
SettingValue.CHAT_TEAM -> sendTeamChat(context.matchPlayer.party, context, event.message)
else -> sendGlobalChat(match, context, event.message)
}
}

val matchPlayer = PGM.get().matchManager.getPlayer(player)!!
Expand Down

0 comments on commit 67e3d54

Please sign in to comment.