From c5538e07424352aa1267bfb611d1993de9d4f08b Mon Sep 17 00:00:00 2001 From: bluefireoly Date: Tue, 1 Sep 2020 22:36:52 +0200 Subject: [PATCH] Updated Locations api --- .../extensions/geometry/KSpigotLocations.kt | 17 +++++++++++++++-- .../net/axay/kspigot/structures/Circle.kt | 6 +++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt b/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt index 79c28b28..cf89e1b8 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt @@ -1,5 +1,18 @@ package net.axay.kspigot.extensions.geometry -data class SimpleLocation2D(val x: Number, val y: Number) +import org.bukkit.Location +import org.bukkit.World -data class SimpleLocation3D(val x: Number, val y: Number, val z: Number) \ No newline at end of file +data class SimpleLocation2D(val x: Double, val y: Double) { + constructor(x: Number, y: Number) : this(x.toDouble(), y.toDouble()) +} + +data class SimpleLocation3D(val x: Double, val y: Double, val z: Double) { + constructor(x: Number, y: Number, z: Number) : this(x.toDouble(), y.toDouble(), z.toDouble()) +} + +// EXTENSIONS + +fun SimpleLocation3D.withWorld(world: World) = Location(world, x, y, z) + +val Location.worldOrException: World get() = world ?: throw NullPointerException("The world of the location is null!") \ No newline at end of file diff --git a/src/main/kotlin/net/axay/kspigot/structures/Circle.kt b/src/main/kotlin/net/axay/kspigot/structures/Circle.kt index bd504970..b572de27 100644 --- a/src/main/kotlin/net/axay/kspigot/structures/Circle.kt +++ b/src/main/kotlin/net/axay/kspigot/structures/Circle.kt @@ -56,17 +56,17 @@ abstract class Circle(val radius: Number) { final fun buildAtX(loc: Location) { for (it in fillLocations) - setAt(Location(loc.world, loc.x, loc.y + it.x.toDouble(), loc.z + it.x.toDouble())) + setAt(Location(loc.world, loc.x, loc.y + it.x, loc.z + it.x)) } final fun buildAtY(loc: Location) { for (it in fillLocations) - setAt(Location(loc.world, loc.x + it.x.toDouble(), loc.y, loc.z + it.x.toDouble())) + setAt(Location(loc.world, loc.x + it.x, loc.y, loc.z + it.x)) } final fun buildAtZ(loc: Location) { for (it in fillLocations) - setAt(Location(loc.world, loc.x + it.x.toDouble(), loc.y + it.x.toDouble(), loc.z)) + setAt(Location(loc.world, loc.x + it.x, loc.y + it.x, loc.z)) } abstract fun setAt(loc: Location)