From 2c98cacf9628c4516eeae6781fd5bbc4c526f702 Mon Sep 17 00:00:00 2001 From: Logan Gorence Date: Thu, 23 Dec 2021 23:05:29 +0000 Subject: [PATCH] Reorganize feature + module init to fix bug. --- .../foundation/core/FoundationCorePlugin.kt | 27 +++++++++---------- .../core/abstraction/FoundationPlugin.kt | 11 +++++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/FoundationCorePlugin.kt b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/FoundationCorePlugin.kt index 488df17..e04e83e 100644 --- a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/FoundationCorePlugin.kt +++ b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/FoundationCorePlugin.kt @@ -1,6 +1,5 @@ package cloud.kubelet.foundation.core -import cloud.kubelet.foundation.core.abstraction.Feature import cloud.kubelet.foundation.core.abstraction.FoundationPlugin import cloud.kubelet.foundation.core.features.backup.BackupFeature import cloud.kubelet.foundation.core.features.dev.DevFeature @@ -13,15 +12,6 @@ import java.nio.file.Path class FoundationCorePlugin : FoundationPlugin() { private lateinit var _pluginDataPath: Path - override val features: List - get() = listOf( - BackupFeature(), - DevFeature(), - PlayerFeature(), - StatsFeature(), - UpdateFeature(), - WorldFeature(), - ) var pluginDataPath: Path /** @@ -38,10 +28,6 @@ class FoundationCorePlugin : FoundationPlugin() { _pluginDataPath = value } - override fun module() = module { - single { this@FoundationCorePlugin } - } - override fun onEnable() { // Create core plugin directory. pluginDataPath = dataFolder.toPath() @@ -49,4 +35,17 @@ class FoundationCorePlugin : FoundationPlugin() { super.onEnable() } + + override fun createFeatures() = listOf( + BackupFeature(), + DevFeature(), + PlayerFeature(), + StatsFeature(), + UpdateFeature(), + WorldFeature(), + ) + + override fun createModule() = module { + single { this@FoundationCorePlugin } + } } diff --git a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/abstraction/FoundationPlugin.kt b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/abstraction/FoundationPlugin.kt index 78241d2..60da082 100644 --- a/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/abstraction/FoundationPlugin.kt +++ b/foundation-core/src/main/kotlin/cloud/kubelet/foundation/core/abstraction/FoundationPlugin.kt @@ -10,7 +10,8 @@ import org.koin.dsl.module abstract class FoundationPlugin : JavaPlugin() { private lateinit var pluginModule: Module private lateinit var pluginApplication: KoinApplication - protected abstract val features: List + private lateinit var features: List + private lateinit var module: Module override fun onEnable() { pluginModule = module { @@ -20,11 +21,14 @@ abstract class FoundationPlugin : JavaPlugin() { single { slF4JLogger } } + features = createFeatures() + module = createModule() + // TODO: If we have another plugin using this class, we may need to use context isolation. // https://insert-koin.io/docs/reference/koin-core/context-isolation pluginApplication = startKoin { modules(pluginModule) - modules(module()) + modules(module) } features.forEach { @@ -50,5 +54,6 @@ abstract class FoundationPlugin : JavaPlugin() { stopKoin() } - protected open fun module() = module {} + protected open fun createModule() = module {} + protected abstract fun createFeatures(): List }