diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt index 766cf1f..0ffaad5 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/features/FeatureManager.kt @@ -1,27 +1,42 @@ package moe.nea.notenoughupdates.features +import kotlinx.serialization.Serializable import kotlinx.serialization.serializer import moe.nea.notenoughupdates.NotEnoughUpdates import moe.nea.notenoughupdates.features.world.FairySouls -import moe.nea.notenoughupdates.util.ConfigHolder +import moe.nea.notenoughupdates.util.config.ConfigHolder object FeatureManager : ConfigHolder<FeatureManager.Config>(serializer(), "features", ::Config) { + @Serializable data class Config( val enabledFeatures: MutableMap<String, Boolean> = mutableMapOf() ) private val features = mutableMapOf<String, NEUFeature>() + private var hasAutoloaded = false + + init { + autoload() + } + fun autoload() { - loadFeature(FairySouls) + synchronized(this) { + if (hasAutoloaded) return + loadFeature(FairySouls) + hasAutoloaded = true + } } fun loadFeature(feature: NEUFeature) { - if (feature.identifier in features) { - NotEnoughUpdates.logger.error("Double registering feature ${feature.identifier}. Ignoring second instance $feature") - return + synchronized(features) { + if (feature.identifier in features) { + NotEnoughUpdates.logger.error("Double registering feature ${feature.identifier}. Ignoring second instance $feature") + return + } + features[feature.identifier] = feature + feature.onLoad() } - features[feature.identifier] = feature } fun isEnabled(identifier: String): Boolean? = |