aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events/subscription
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-09-01 22:21:19 +0200
committerLinnea Gräf <nea@nea.moe>2024-09-01 22:21:19 +0200
commit5ed74f2df49c93ed1617520a935078b59ad7e195 (patch)
treef0d52699fff7f820bd724902878988859bd43516 /src/main/kotlin/events/subscription
parent816f80f862d2f5de6bc9b0ae84cd6df0da341228 (diff)
downloadFirmament-5ed74f2df49c93ed1617520a935078b59ad7e195.tar.gz
Firmament-5ed74f2df49c93ed1617520a935078b59ad7e195.tar.bz2
Firmament-5ed74f2df49c93ed1617520a935078b59ad7e195.zip
Add per compat project event listeners
[no changelog]
Diffstat (limited to 'src/main/kotlin/events/subscription')
-rw-r--r--src/main/kotlin/events/subscription/Subscription.kt1
-rw-r--r--src/main/kotlin/events/subscription/SubscriptionList.kt25
2 files changed, 26 insertions, 0 deletions
diff --git a/src/main/kotlin/events/subscription/Subscription.kt b/src/main/kotlin/events/subscription/Subscription.kt
index 83b91c9..1c1d3bd 100644
--- a/src/main/kotlin/events/subscription/Subscription.kt
+++ b/src/main/kotlin/events/subscription/Subscription.kt
@@ -13,4 +13,5 @@ data class Subscription<T : FirmamentEvent>(
val owner: Any,
val invoke: (T) -> Unit,
val eventBus: FirmamentEventBus<T>,
+ val methodName: String,
)
diff --git a/src/main/kotlin/events/subscription/SubscriptionList.kt b/src/main/kotlin/events/subscription/SubscriptionList.kt
new file mode 100644
index 0000000..e74a65a
--- /dev/null
+++ b/src/main/kotlin/events/subscription/SubscriptionList.kt
@@ -0,0 +1,25 @@
+package moe.nea.firmament.events.subscription
+
+import java.util.ServiceLoader
+import kotlin.streams.asSequence
+import moe.nea.firmament.Firmament
+
+interface SubscriptionList {
+ fun provideSubscriptions(addSubscription: (Subscription<*>) -> Unit)
+
+ companion object {
+ val allLists by lazy {
+ ServiceLoader.load(SubscriptionList::class.java)
+ .stream()
+ .asSequence()
+ .mapNotNull {
+ kotlin.runCatching { it.get() }
+ .getOrElse { ex ->
+ Firmament.logger.error("Could not load subscriptions from ${it.type()}", ex)
+ null
+ }
+ }
+ .toList()
+ }
+ }
+}