diff options
author | Linnea Gräf <nea@nea.moe> | 2024-05-07 20:26:04 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-05-07 20:26:04 +0200 |
commit | 8f3cc34740fcfe1572d23c8f1c1db1a309217b84 (patch) | |
tree | 1a4d7922b8ec1785e0c1f52fcdf85f3e33f16859 /src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt | |
parent | 0cb976ce078b9b0217c9a8e5763638764d89a31e (diff) | |
download | firmament-8f3cc34740fcfe1572d23c8f1c1db1a309217b84.tar.gz firmament-8f3cc34740fcfe1572d23c8f1c1db1a309217b84.tar.bz2 firmament-8f3cc34740fcfe1572d23c8f1c1db1a309217b84.zip |
Add @Subscribe annotation
[no changelog]
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt index a8daf63..669b3c9 100644 --- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt +++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt @@ -10,7 +10,10 @@ package moe.nea.firmament.features import kotlinx.serialization.Serializable import kotlinx.serialization.serializer import moe.nea.firmament.Firmament +import moe.nea.firmament.annotations.generated.AllSubscriptions import moe.nea.firmament.events.FeaturesInitializedEvent +import moe.nea.firmament.events.FirmamentEvent +import moe.nea.firmament.events.subscription.Subscription import moe.nea.firmament.features.chat.AutoCompletions import moe.nea.firmament.features.chat.ChatLinks import moe.nea.firmament.features.chat.QuickCommands @@ -80,11 +83,26 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature loadFeature(DebugView) } allFeatures.forEach { it.config } + subscribeEvents() FeaturesInitializedEvent.publish(FeaturesInitializedEvent(allFeatures.toList())) hasAutoloaded = true } } + private fun subscribeEvents() { + AllSubscriptions.provideSubscriptions { + subscribeSingleEvent(it) + } + } + + private fun <T : FirmamentEvent> subscribeSingleEvent(it: Subscription<T>) { + if (it.owner in features.values) { // TODO: better check here, somehow. probably implement some interface method + it.eventBus.subscribe(false, it.invoke) // TODO: pass through receivesCancelled from the annotation + } else { + Firmament.logger.error("Ignoring event listener for ${it.eventBus} in ${it.owner}") + } + } + fun loadFeature(feature: FirmamentFeature) { synchronized(features) { if (feature.identifier in features) { |