aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events/subscription
diff options
context:
space:
mode:
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()
+ }
+ }
+}