From 1f038416daef4255f8546eca6f178f7b2d10795d Mon Sep 17 00:00:00 2001 From: bluefireoly Date: Sat, 12 Sep 2020 13:22:21 +0200 Subject: [PATCH] Chunk support in LocationArea --- .../kspigot/extensions/geometry/LocationArea.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/geometry/LocationArea.kt b/src/main/kotlin/net/axay/kspigot/extensions/geometry/LocationArea.kt index cbc4ba9d..a78162fc 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/geometry/LocationArea.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/geometry/LocationArea.kt @@ -2,6 +2,7 @@ package net.axay.kspigot.extensions.geometry +import org.bukkit.Chunk import org.bukkit.Location import org.bukkit.World import kotlin.math.max @@ -38,6 +39,19 @@ class SimpleLocationPair(loc1: Location, loc2: Location) { } + val touchedChunks: Set by lazy { + + val foundChunks = HashSet() + + (minLoc.chunk.x until maxLoc.chunk.x + 1).forEach { curX -> + (minLoc.chunk.z until maxLoc.chunk.z + 1).forEach { curZ -> + foundChunks += SimpleChunkLocation(curX, curZ) + } } + + return@lazy foundChunks + + } + } class LocationArea(loc1: Location, loc2: Location) { @@ -59,4 +73,6 @@ class LocationArea(loc1: Location, loc2: Location) { val minLoc: Location get() = locationPair.minLoc.withWorld(locationPair.world) val maxLoc: Location get() = locationPair.maxLoc.withWorld(locationPair.world) + val touchedChunks: Set get() = locationPair.touchedChunks.mapTo(HashSet()) { it.withWorld(world) } + } \ No newline at end of file