Skip to content

Commit

Permalink
Fix Sections not being registered with WorldManager (#96)
Browse files Browse the repository at this point in the history
* change config classes

* fix sections not registering in the sectionmap
  • Loading branch information
Boy0000 authored Nov 7, 2022
1 parent d1b605a commit a5794c9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
31 changes: 14 additions & 17 deletions src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Section> = 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<Section> = 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<World, Long> = 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(),
)
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +11,7 @@ import org.bukkit.World
class WorldManagerImpl : WorldManager {
override val sections get() = sectionMap.values.toSet()

private val sectionMap: MutableMap<SectionKey, Section> = HashMap()
private val sectionMap = deeperConfig.sections.associateBy { it.key }.toMutableMap()


override fun registerSection(name: String, section: Section): SectionKey =
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a5794c9

Please sign in to comment.