From 7c5f31bb42f977fdd7013048fad12cf04961eba4 Mon Sep 17 00:00:00 2001 From: andyksaw Date: Tue, 26 Nov 2024 21:20:17 +0900 Subject: [PATCH] Add coroutine exception listener --- .../projectcitybuild/pcbridge/paper/Container.kt | 16 ++++++++++++---- .../projectcitybuild/pcbridge/paper/Plugin.kt | 11 +++++++---- .../events/PlayerStateDestroyedEvent.kt | 2 +- .../events/PlayerStateUpdatedEvent.kt | 2 +- .../architecture/listeners/ExceptionListener.kt | 15 +++++++++++++++ .../listeners/PlayerStateListener.kt | 6 +++--- .../listeners/PlayerSyncRequestListener.kt | 4 ++-- .../listeners/AuthorizeConnectionListener.kt | 2 +- .../chat/listeners/SyncPlayerChatListener.kt | 2 +- .../features/groups/listener/SyncRankListener.kt | 2 +- 10 files changed, 44 insertions(+), 18 deletions(-) rename pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/{playerstate => architecture}/events/PlayerStateDestroyedEvent.kt (86%) rename pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/{playerstate => architecture}/events/PlayerStateUpdatedEvent.kt (87%) create mode 100644 pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/ExceptionListener.kt rename pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/{playerstate => architecture}/listeners/PlayerStateListener.kt (89%) rename pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/{playerstate => architecture}/listeners/PlayerSyncRequestListener.kt (92%) diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Container.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Container.kt index 7599a4a0..1a22d5dc 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Container.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Container.kt @@ -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 @@ -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 @@ -95,6 +96,7 @@ fun pluginModule(_plugin: JavaPlugin) = // Features announcements() + architecture() bans() builds() chat() @@ -102,7 +104,6 @@ fun pluginModule(_plugin: JavaPlugin) = joinMessages() invisFrames() nightVision() - playerState() register() staffChat() telemetry() @@ -433,7 +434,7 @@ private fun Module.joinMessages() { } } -private fun Module.playerState() { +private fun Module.architecture() { factory { PlayerStateListener( store = get(), @@ -441,6 +442,7 @@ private fun Module.playerState() { eventBroadcaster = get(), ) } + factory { PlayerSyncRequestListener( store = get(), @@ -450,6 +452,12 @@ private fun Module.playerState() { playerRepository = get(), ) } + + factory { + ExceptionListener( + sentryReporter = get(), + ) + } } private fun Module.bans() { diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Plugin.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Plugin.kt index 32e96345..cd9d1b5b 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Plugin.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/Plugin.kt @@ -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 @@ -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 @@ -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 @@ -146,6 +148,7 @@ private class Lifecycle : KoinComponent { get(), get(), get(), + get(), get(), get(), get(), @@ -176,7 +179,7 @@ private class Lifecycle : KoinComponent { get().enable() get().enable() - get().startProcessing() + get().startProcessing() } suspend fun shutdown() = @@ -189,7 +192,7 @@ private class Lifecycle : KoinComponent { get().disable() get().disable() - get().stopProcessing() + get().stopProcessing() listenerRegistry.unregisterAll() commandRegistry.unregisterAll() diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/events/PlayerStateDestroyedEvent.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/events/PlayerStateDestroyedEvent.kt similarity index 86% rename from pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/events/PlayerStateDestroyedEvent.kt rename to pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/events/PlayerStateDestroyedEvent.kt index 5a7d399f..0bf37589 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/events/PlayerStateDestroyedEvent.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/events/PlayerStateDestroyedEvent.kt @@ -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 diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/events/PlayerStateUpdatedEvent.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/events/PlayerStateUpdatedEvent.kt similarity index 87% rename from pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/events/PlayerStateUpdatedEvent.kt rename to pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/events/PlayerStateUpdatedEvent.kt index ec2bed9a..150db6ab 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/events/PlayerStateUpdatedEvent.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/events/PlayerStateUpdatedEvent.kt @@ -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 diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/ExceptionListener.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/ExceptionListener.kt new file mode 100644 index 00000000..e1d78afb --- /dev/null +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/ExceptionListener.kt @@ -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) + } +} \ No newline at end of file diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/listeners/PlayerStateListener.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/PlayerStateListener.kt similarity index 89% rename from pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/listeners/PlayerStateListener.kt rename to pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/PlayerStateListener.kt index 80fbeaf9..5597c4aa 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/listeners/PlayerStateListener.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/PlayerStateListener.kt @@ -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 diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/listeners/PlayerSyncRequestListener.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/PlayerSyncRequestListener.kt similarity index 92% rename from pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/listeners/PlayerSyncRequestListener.kt rename to pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/PlayerSyncRequestListener.kt index 67266b37..e7cfe81e 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/playerstate/listeners/PlayerSyncRequestListener.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/architecture/listeners/PlayerSyncRequestListener.kt @@ -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 diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/bans/listeners/AuthorizeConnectionListener.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/bans/listeners/AuthorizeConnectionListener.kt index ae17fdc7..14e119ce 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/bans/listeners/AuthorizeConnectionListener.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/bans/listeners/AuthorizeConnectionListener.kt @@ -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 diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/chat/listeners/SyncPlayerChatListener.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/chat/listeners/SyncPlayerChatListener.kt index 7ac202d8..48f02b13 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/chat/listeners/SyncPlayerChatListener.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/chat/listeners/SyncPlayerChatListener.kt @@ -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 diff --git a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/groups/listener/SyncRankListener.kt b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/groups/listener/SyncRankListener.kt index 6ddacde2..7bea693e 100644 --- a/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/groups/listener/SyncRankListener.kt +++ b/pcbridge-paper/src/main/kotlin/com/projectcitybuild/pcbridge/paper/features/groups/listener/SyncRankListener.kt @@ -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