aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events/subscription/SubscriptionList.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/events/subscription/SubscriptionList.kt')
-rw-r--r--src/main/kotlin/events/subscription/SubscriptionList.kt25
1 files changed, 25 insertions, 0 deletions
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()
+ }
+ }
+}