Added SerializableWorld
This commit is contained in:
@@ -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() }
|
||||
|
||||
}
|
@@ -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")
|
||||
|
||||
}
|
Reference in New Issue
Block a user