Added SerializableWorld

This commit is contained in:
bluefireoly
2020-10-23 17:44:54 +02:00
parent f99883a15f
commit 6d709d2a64
2 changed files with 24 additions and 4 deletions

View File

@@ -4,11 +4,10 @@ package net.axay.kspigot.serialization.serializables
import net.axay.kspigot.serialization.SpigotSerializable
import net.axay.kspigot.serialization.SpigotSerializableCompanion
import org.bukkit.Bukkit
import org.bukkit.Location
data class SerializableLocation(
val world: String?,
val world: SerializableWorld?,
val x: Double,
val y: Double,
val z: Double,
@@ -17,9 +16,9 @@ data class SerializableLocation(
companion object : SpigotSerializableCompanion<SerializableLocation>
constructor(loc: Location) : this(loc.world?.name, loc.x, loc.y, loc.z, SerializableVector(loc.direction))
constructor(loc: Location) : this(loc.world?.let { SerializableWorld(it) }, loc.x, loc.y, loc.z, SerializableVector(loc.direction))
override fun toSpigot() = Location(world?.let { Bukkit.getWorld(world) }, x, y, z)
override fun toSpigot() = Location(world?.toSpigot(), x, y, z)
.apply { direction = this@SerializableLocation.direction.toSpigot() }
}

View File

@@ -0,0 +1,21 @@
@file:Suppress("MemberVisibilityCanBePrivate")
package net.axay.kspigot.serialization.serializables
import net.axay.kspigot.serialization.SpigotSerializable
import net.axay.kspigot.serialization.SpigotSerializableCompanion
import org.bukkit.Bukkit
import org.bukkit.World
class SerializableWorld(
val name: String
) : SpigotSerializable<World> {
companion object : SpigotSerializableCompanion<World>
constructor(world: World) : this(world.name)
override fun toSpigot() = Bukkit.getWorld(name)
?: throw NullPointerException("The world \"$name\" does not exist")
}