Reorganize feature + module init to fix bug.

This commit is contained in:
Logan Gorence 2021-12-23 23:05:29 +00:00
parent c854e7c47c
commit 2c98cacf96
No known key found for this signature in database
GPG Key ID: 9743CEF10935949A
2 changed files with 21 additions and 17 deletions

View File

@ -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<Feature>
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 }
}
}

View File

@ -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<Feature>
private lateinit var features: List<Feature>
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<Feature>
}