diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt b/src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt index bae4222..d703bb1 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt @@ -12,34 +12,31 @@ import org.bukkit.World import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds -val deeperConfig get() = deeperWorld.config.data.deeperConfig +val deeperConfig get() = deeperWorld.config.data @Serializable -data class DeeperWorldConfig(val deeperConfig: DeeperConfig = DeeperConfig()) { - @Serializable - data class DeeperConfig( - val sections: List
= emptyList(), - val damageOutsideSections: Double = 0.0, - val damageExcludedWorlds: Set<@Serializable(with = WorldSerializer::class) World> = emptySet(), - val remountPacketDelay: Duration = 40.ticks, - val fall: FallDamageConfig = FallDamageConfig(), - val time: TimeConfig = TimeConfig(), - ) { - val worlds = sections.map { it.world }.toSet() - } +data class DeeperWorldConfig( + val sections: List
= emptyList(), + val damageOutsideSections: Double = 0.0, + val damageExcludedWorlds: Set<@Serializable(with = WorldSerializer::class) World> = emptySet(), + val remountPacketDelay: Duration = 40.ticks, + val fall: FallDamageConfig = FallDamageConfig(), + val time: TimeConfig = TimeConfig(), +) { + val worlds = sections.map { it.world }.toSet() @Serializable data class FallDamageConfig( val maxSafeDist: Float = -1f, val fallDistanceDamageScaler: Double = 0.01, val startingDamage: Double = 1.0, - val hitDelay: Duration = 10.ticks, + val hitDelay: @Serializable(DurationSerializer::class) Duration = 10.ticks, val spawnParticles: Boolean = true ) @Serializable data class TimeConfig( - val updateInterval: Duration = 1800.seconds, - val mainWorld: World? = null, - val syncedWorlds: Map = emptyMap(), + val updateInterval: @Serializable(DurationSerializer::class) Duration = 1800.seconds, + val mainWorld: @Serializable(WorldSerializer::class) World? = null, + val syncedWorlds: Map<@Serializable(WorldSerializer::class) World, Long> = emptyMap(), ) } diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/world/WorldManagerImpl.kt b/src/main/kotlin/com/mineinabyss/deeperworld/world/WorldManagerImpl.kt index 2d26816..9d29927 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/world/WorldManagerImpl.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/world/WorldManagerImpl.kt @@ -1,5 +1,6 @@ package com.mineinabyss.deeperworld.world +import com.mineinabyss.deeperworld.deeperConfig import com.mineinabyss.deeperworld.services.WorldManager import com.mineinabyss.deeperworld.world.section.AbstractSectionKey.CustomSectionKey import com.mineinabyss.deeperworld.world.section.Section @@ -10,7 +11,7 @@ import org.bukkit.World class WorldManagerImpl : WorldManager { override val sections get() = sectionMap.values.toSet() - private val sectionMap: MutableMap = HashMap() + private val sectionMap = deeperConfig.sections.associateBy { it.key }.toMutableMap() override fun registerSection(name: String, section: Section): SectionKey = @@ -20,7 +21,7 @@ class WorldManagerImpl : WorldManager { registerInternal(sectionKey, section) private fun registerInternal(key: SectionKey, section: Section): SectionKey { - if (sectionMap.containsKey(key)) throw RuntimeException("Bruh") //TODO change to checked exception + if (key in sectionMap) throw RuntimeException("Bruh") //TODO change to checked exception sectionMap[key] = section return key } diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/world/section/Section.kt b/src/main/kotlin/com/mineinabyss/deeperworld/world/section/Section.kt index d48a325..6108148 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/world/section/Section.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/world/section/Section.kt @@ -27,9 +27,9 @@ import org.bukkit.util.Vector data class Section( val name: String? = null, val region: Region, - val world: World, - @SerialName("refTop") private val _refTop: Vector, - @SerialName("refBottom") private val _refBottom: Vector + val world: @Serializable(WorldSerializer::class) World, + @SerialName("refTop") private val _refTop: @Serializable(VectorSerializer::class) Vector, + @SerialName("refBottom") private val _refBottom: @Serializable(VectorSerializer::class) Vector ) { @Transient val referenceTop = _refTop.toLocation(world)