Skip to content

Commit

Permalink
Add coroutine exception listener
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw committed Nov 26, 2024
1 parent 040a455 commit 7c5f31b
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.Annou
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.FirstTimeJoinListener
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.ServerOverviewJoinListener
import com.projectcitybuild.pcbridge.paper.features.nightvision.commands.NightVisionCommand
import com.projectcitybuild.pcbridge.paper.features.playerstate.listeners.PlayerStateListener
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.PlayerStateListener
import com.projectcitybuild.pcbridge.paper.features.register.commands.CodeCommand
import com.projectcitybuild.pcbridge.paper.features.register.commands.RegisterCommand
import com.projectcitybuild.pcbridge.paper.features.staffchat.commands.StaffChatCommand
import com.projectcitybuild.pcbridge.paper.features.groups.actions.SyncPlayerGroups
import com.projectcitybuild.pcbridge.paper.features.groups.commands.SyncCommand
import com.projectcitybuild.pcbridge.paper.features.groups.listener.SyncRankListener
import com.projectcitybuild.pcbridge.paper.features.playerstate.listeners.PlayerSyncRequestListener
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.PlayerSyncRequestListener
import com.projectcitybuild.pcbridge.paper.features.telemetry.listeners.TelemetryPlayerConnectListener
import com.projectcitybuild.pcbridge.paper.features.telemetry.repositories.TelemetryRepository
import com.projectcitybuild.pcbridge.paper.features.warps.commands.WarpCommand
Expand All @@ -71,6 +71,7 @@ import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotEventBroadc
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotListenerRegistry
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotNamespace
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotTimer
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.ExceptionListener
import com.projectcitybuild.pcbridge.webserver.HttpServer
import com.projectcitybuild.pcbridge.webserver.HttpServerConfig
import io.github.reactivecircus.cache4k.Cache
Expand All @@ -95,14 +96,14 @@ fun pluginModule(_plugin: JavaPlugin) =

// Features
announcements()
architecture()
bans()
builds()
chat()
groups()
joinMessages()
invisFrames()
nightVision()
playerState()
register()
staffChat()
telemetry()
Expand Down Expand Up @@ -433,14 +434,15 @@ private fun Module.joinMessages() {
}
}

private fun Module.playerState() {
private fun Module.architecture() {
factory {
PlayerStateListener(
store = get(),
time = get(),
eventBroadcaster = get(),
)
}

factory {
PlayerSyncRequestListener(
store = get(),
Expand All @@ -450,6 +452,12 @@ private fun Module.playerState() {
playerRepository = get(),
)
}

factory {
ExceptionListener(
sentryReporter = get(),
)
}
}

private fun Module.bans() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.projectcitybuild.pcbridge.paper

import com.github.shynixn.mccoroutine.bukkit.SuspendingJavaPlugin
import com.projectcitybuild.pcbridge.paper.core.libs.discord.DiscordSend
import com.projectcitybuild.pcbridge.paper.core.libs.errors.SentryReporter
import com.projectcitybuild.pcbridge.paper.core.libs.errors.trace
import com.projectcitybuild.pcbridge.paper.core.libs.remoteconfig.commands.ConfigCommand
Expand All @@ -25,12 +26,12 @@ import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.Annou
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.FirstTimeJoinListener
import com.projectcitybuild.pcbridge.paper.features.joinmessages.listeners.ServerOverviewJoinListener
import com.projectcitybuild.pcbridge.paper.features.nightvision.commands.NightVisionCommand
import com.projectcitybuild.pcbridge.paper.features.playerstate.listeners.PlayerStateListener
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.PlayerStateListener
import com.projectcitybuild.pcbridge.paper.features.register.commands.CodeCommand
import com.projectcitybuild.pcbridge.paper.features.register.commands.RegisterCommand
import com.projectcitybuild.pcbridge.paper.features.staffchat.commands.StaffChatCommand
import com.projectcitybuild.pcbridge.paper.features.groups.listener.SyncRankListener
import com.projectcitybuild.pcbridge.paper.features.playerstate.listeners.PlayerSyncRequestListener
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.PlayerSyncRequestListener
import com.projectcitybuild.pcbridge.paper.features.telemetry.listeners.TelemetryPlayerConnectListener
import com.projectcitybuild.pcbridge.paper.features.warps.commands.WarpCommand
import com.projectcitybuild.pcbridge.paper.features.warps.commands.WarpsCommand
Expand All @@ -42,6 +43,7 @@ import com.projectcitybuild.pcbridge.paper.integrations.LuckPermsIntegration
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotCommandRegistry
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotListenerRegistry
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotTimer
import com.projectcitybuild.pcbridge.paper.features.architecture.listeners.ExceptionListener
import com.projectcitybuild.pcbridge.webserver.HttpServer
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents
import net.kyori.adventure.platform.bukkit.BukkitAudiences
Expand Down Expand Up @@ -146,6 +148,7 @@ private class Lifecycle : KoinComponent {
get<AnnouncementEnableListener>(),
get<AuthorizeConnectionListener>(),
get<ChatConfigListener>(),
get<ExceptionListener>(),
get<FirstTimeJoinListener>(),
get<FormatNameChatListener>(),
get<FramePlaceListener>(),
Expand Down Expand Up @@ -176,7 +179,7 @@ private class Lifecycle : KoinComponent {
get<EssentialsIntegration>().enable()
get<LuckPermsIntegration>().enable()

get<com.projectcitybuild.pcbridge.paper.core.libs.discord.DiscordSend>().startProcessing()
get<DiscordSend>().startProcessing()
}

suspend fun shutdown() =
Expand All @@ -189,7 +192,7 @@ private class Lifecycle : KoinComponent {
get<EssentialsIntegration>().disable()
get<LuckPermsIntegration>().disable()

get<com.projectcitybuild.pcbridge.paper.core.libs.discord.DiscordSend>().stopProcessing()
get<DiscordSend>().stopProcessing()

listenerRegistry.unregisterAll()
commandRegistry.unregisterAll()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.paper.features.playerstate.events
package com.projectcitybuild.pcbridge.paper.features.architecture.events

import com.projectcitybuild.pcbridge.paper.core.libs.store.PlayerState
import org.bukkit.event.Event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projectcitybuild.pcbridge.paper.features.playerstate.events
package com.projectcitybuild.pcbridge.paper.features.architecture.events

import com.projectcitybuild.pcbridge.paper.core.libs.store.PlayerState
import org.bukkit.event.Event
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.projectcitybuild.pcbridge.paper.features.architecture.listeners

import com.github.shynixn.mccoroutine.bukkit.MCCoroutineExceptionEvent
import com.projectcitybuild.pcbridge.paper.core.libs.errors.SentryReporter
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener

class ExceptionListener(
private val sentryReporter: SentryReporter,
): Listener {
@EventHandler
fun onException(event: MCCoroutineExceptionEvent) {
sentryReporter.report(event.exception)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.projectcitybuild.pcbridge.paper.features.playerstate.listeners
package com.projectcitybuild.pcbridge.paper.features.architecture.listeners

import com.projectcitybuild.pcbridge.paper.core.libs.datetime.services.LocalizedTime
import com.projectcitybuild.pcbridge.paper.core.libs.logger.log
import com.projectcitybuild.pcbridge.paper.core.libs.store.PlayerState
import com.projectcitybuild.pcbridge.paper.core.libs.store.Store
import com.projectcitybuild.pcbridge.paper.features.bans.events.ConnectionPermittedEvent
import com.projectcitybuild.pcbridge.paper.features.playerstate.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.playerstate.events.PlayerStateDestroyedEvent
import com.projectcitybuild.pcbridge.paper.features.architecture.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.architecture.events.PlayerStateDestroyedEvent
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotEventBroadcaster
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.projectcitybuild.pcbridge.paper.features.playerstate.listeners
package com.projectcitybuild.pcbridge.paper.features.architecture.listeners

import com.projectcitybuild.pcbridge.paper.core.libs.datetime.services.LocalizedTime
import com.projectcitybuild.pcbridge.paper.core.libs.logger.log
import com.projectcitybuild.pcbridge.paper.core.libs.store.PlayerState
import com.projectcitybuild.pcbridge.paper.core.libs.store.Store
import com.projectcitybuild.pcbridge.paper.features.bans.repositories.PlayerRepository
import com.projectcitybuild.pcbridge.paper.features.playerstate.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.architecture.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.groups.events.PlayerSyncRequestedEvent
import com.projectcitybuild.pcbridge.paper.core.support.spigot.SpigotEventBroadcaster
import net.kyori.adventure.text.minimessage.MiniMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AuthorizeConnectionListener(
private val sentry: SentryReporter,
) : Listener {
@EventHandler(priority = EventPriority.HIGHEST)
suspend fun handle(event: AsyncPlayerPreLoginEvent) {
fun handle(event: AsyncPlayerPreLoginEvent) {
/**
* In order to call `event.disallow()`, this function must block until player data
* has been fetched and processed. Blocking is not a problem because this event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.projectcitybuild.pcbridge.paper.features.chat.listeners
import com.projectcitybuild.pcbridge.paper.core.libs.logger.log
import com.projectcitybuild.pcbridge.paper.features.chat.repositories.ChatBadgeRepository
import com.projectcitybuild.pcbridge.paper.features.chat.repositories.ChatGroupRepository
import com.projectcitybuild.pcbridge.paper.features.playerstate.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.architecture.events.PlayerStateUpdatedEvent
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.projectcitybuild.pcbridge.paper.features.groups.listener

import com.projectcitybuild.pcbridge.paper.features.playerstate.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.architecture.events.PlayerStateUpdatedEvent
import com.projectcitybuild.pcbridge.paper.features.groups.actions.SyncPlayerGroups
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
Expand Down

0 comments on commit 7c5f31b

Please sign in to comment.