diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/DeeperWorldPlugin.kt b/src/main/kotlin/com/mineinabyss/deeperworld/DeeperWorldPlugin.kt index ba31b25..5f1fc5c 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/DeeperWorldPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/DeeperWorldPlugin.kt @@ -38,6 +38,18 @@ class DeeperWorldPlugin : JavaPlugin() { service(WorldManagerImpl()) service(PlayerManagerImpl()) + // Register aboveKey / belowKey as new config breaks this + for (section in deeperConfig.sections) { + when (section) { + deeperConfig.sections.first() -> section.belowKey = deeperConfig.sections[1].key + deeperConfig.sections.last() -> section.aboveKey = deeperConfig.sections[deeperConfig.sections.size - 2].key + else -> { + section.aboveKey = deeperConfig.sections[deeperConfig.sections.indexOf(section) - 1].key + section.belowKey = deeperConfig.sections[deeperConfig.sections.indexOf(section) + 1].key + } + } + } + listeners( MovementListener, PlayerListener, diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/world/Region.kt b/src/main/kotlin/com/mineinabyss/deeperworld/world/Region.kt index 508a420..d6ef8b8 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/world/Region.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/world/Region.kt @@ -2,8 +2,6 @@ package com.mineinabyss.deeperworld.world import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable -import kotlinx.serialization.builtins.ListSerializer -import kotlinx.serialization.builtins.serializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -33,14 +31,17 @@ class Region(val a: CubePoint, val b: CubePoint) { operator fun contains(p: CubePoint) = contains(p.x, p.y, p.z) } +@Serializable +data class RegionPoints(val x1: Int, val y1: Int, val z1: Int, val x2: Int, val y2: Int, val z2: Int) + object RegionSerializer : KSerializer { - private val serializer = ListSerializer(Int.serializer()) + private val serializer = RegionPoints.serializer() override val descriptor: SerialDescriptor = serializer.descriptor override fun serialize(encoder: Encoder, value: Region) { val (x, y, z) = value.a val (x2, y2, z2) = value.b - encoder.encodeSerializableValue(serializer, listOf(x, y, z, x2, y2, z2)) + encoder.encodeSerializableValue(serializer, RegionPoints(x, y, z, x2, y2, z2)) } override fun deserialize(decoder: Decoder): Region { 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 6108148..6a94864 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/world/section/Section.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/world/section/Section.kt @@ -3,14 +3,15 @@ package com.mineinabyss.deeperworld.world.section import com.mineinabyss.deeperworld.world.Region +import com.mineinabyss.idofront.serialization.LocationSerializer import com.mineinabyss.idofront.serialization.VectorSerializer import com.mineinabyss.idofront.serialization.WorldSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import kotlinx.serialization.UseSerializers +import org.bukkit.Location import org.bukkit.World -import org.bukkit.util.Vector /** * @property region the region within which this section is active @@ -28,16 +29,15 @@ data class Section( val name: String? = null, val region: Region, val world: @Serializable(WorldSerializer::class) World, - @SerialName("refTop") private val _refTop: @Serializable(VectorSerializer::class) Vector, - @SerialName("refBottom") private val _refBottom: @Serializable(VectorSerializer::class) Vector + @SerialName("refTop") private val _refTop: ReferenceLocation, + @SerialName("refBottom") private val _refBottom: ReferenceLocation ) { - @Transient + @Serializable(LocationSerializer::class) val referenceTop = _refTop.toLocation(world) - @Transient + @Serializable(LocationSerializer::class) val referenceBottom = _refBottom.toLocation(world) - @Transient val key: SectionKey = name?.let { AbstractSectionKey.CustomSectionKey(name) } ?: AbstractSectionKey.InternalSectionKey() @@ -49,3 +49,8 @@ data class Section( override fun toString() = key.toString() } + +@Serializable +data class ReferenceLocation(val x: Int, val y: Int, val z: Int) { + fun toLocation(world: World) = Location(world, x.toDouble(), y.toDouble(), z.toDouble()) +}