Updated Locations api

This commit is contained in:
bluefireoly
2020-09-01 22:36:52 +02:00
parent 4087e80cdf
commit c5538e0742
2 changed files with 18 additions and 5 deletions

View File

@@ -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)
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!")

View File

@@ -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)