diff --git a/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt b/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt index ca705db..c26c4e0 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt @@ -2,7 +2,7 @@ package net.trivernis.chunkmaster import io.papermc.lib.PaperLib import net.trivernis.chunkmaster.commands.* -import net.trivernis.chunkmaster.lib.GenerationManager +import net.trivernis.chunkmaster.lib.generation.GenerationManager import net.trivernis.chunkmaster.lib.SqlUpdateManager import org.bukkit.plugin.java.JavaPlugin import org.bukkit.scheduler.BukkitTask diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/ChunkCoordinates.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/ChunkCoordinates.kt new file mode 100644 index 0000000..6c4627f --- /dev/null +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/ChunkCoordinates.kt @@ -0,0 +1,4 @@ +package net.trivernis.chunkmaster.lib.generation + +data class ChunkCoordinates(val x: Int, val z: Int) { +} \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationManager.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt similarity index 99% rename from src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationManager.kt rename to src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt index 3d0bb3b..a4c615c 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationManager.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt @@ -1,4 +1,4 @@ -package net.trivernis.chunkmaster.lib +package net.trivernis.chunkmaster.lib.generation import io.papermc.lib.PaperLib import net.trivernis.chunkmaster.Chunkmaster diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTask.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt similarity index 68% rename from src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTask.kt rename to src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt index 230d843..697abd9 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTask.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt @@ -1,6 +1,7 @@ -package net.trivernis.chunkmaster.lib +package net.trivernis.chunkmaster.lib.generation import net.trivernis.chunkmaster.Chunkmaster +import net.trivernis.chunkmaster.lib.Spiral import org.bukkit.Chunk import org.bukkit.World @@ -15,7 +16,8 @@ abstract class GenerationTask(plugin: Chunkmaster, centerChunk: Chunk, startChun abstract val lastChunk: Chunk abstract val endReached: Boolean - protected val spiral: Spiral = Spiral(Pair(centerChunk.x, centerChunk.z), Pair(startChunk.x, startChunk.z)) + protected val spiral: Spiral = + Spiral(Pair(centerChunk.x, centerChunk.z), Pair(startChunk.x, startChunk.z)) protected val loadedChunks: HashSet = HashSet() protected val chunkSkips = plugin.config.getInt("generation.chunks-skips-per-step") protected val msptThreshold = plugin.config.getLong("generation.mspt-pause-threshold") @@ -23,10 +25,15 @@ abstract class GenerationTask(plugin: Chunkmaster, centerChunk: Chunk, startChun abstract override fun run() abstract fun cancel() - val nextChunk: Chunk + val nextChunkCoordinates: ChunkCoordinates get() { val nextChunkCoords = spiral.next() - return world.getChunkAt(nextChunkCoords.first, nextChunkCoords.second) + return ChunkCoordinates(nextChunkCoords.first, nextChunkCoords.second) + } + val nextChunk: Chunk + get() { + val next = nextChunkCoordinates + return world.getChunkAt(next.x, next.z) } protected fun borderReached(): Boolean { diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTaskPaper.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskPaper.kt similarity index 89% rename from src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTaskPaper.kt rename to src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskPaper.kt index 4703008..67b419c 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTaskPaper.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskPaper.kt @@ -1,4 +1,4 @@ -package net.trivernis.chunkmaster.lib +package net.trivernis.chunkmaster.lib.generation import net.trivernis.chunkmaster.Chunkmaster import org.bukkit.Chunk @@ -17,10 +17,15 @@ class GenerationTaskPaper( override var count = 0 private set override var lastChunk: Chunk = startChunk + get() { + return world.getChunkAt(lastChunkCoords.x, lastChunkCoords.z) + } private set override var endReached: Boolean = false private set + private var lastChunkCoords = ChunkCoordinates(startChunk.x, startChunk.z) + /** * Runs the generation task. Every Iteration the next chunk will be generated if * it hasn't been generated already. @@ -40,10 +45,10 @@ class GenerationTaskPaper( return } - var chunk = nextChunk + var chunk = nextChunkCoordinates for (i in 1 until chunkSkips) { if (PaperLib.isChunkGenerated(world, chunk.x, chunk.z)) { - chunk = nextChunk + chunk = nextChunkCoordinates } else { break } @@ -52,7 +57,7 @@ class GenerationTaskPaper( if (!PaperLib.isChunkGenerated(world, chunk.x, chunk.z)) { pendingChunks.add(PaperLib.getChunkAtAsync(world, chunk.x, chunk.z, true)) } - lastChunk = chunk + lastChunkCoords = chunk count = spiral.count // set the count to the more accurate spiral count } } diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTaskSpigot.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskSpigot.kt similarity index 92% rename from src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTaskSpigot.kt rename to src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskSpigot.kt index 9aa831f..0032a51 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/GenerationTaskSpigot.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskSpigot.kt @@ -1,11 +1,8 @@ -package net.trivernis.chunkmaster.lib +package net.trivernis.chunkmaster.lib.generation import net.trivernis.chunkmaster.Chunkmaster import org.bukkit.Chunk import org.bukkit.World -import org.bukkit.scheduler.BukkitRunnable -import org.bukkit.scheduler.BukkitTask -import java.util.concurrent.CompletableFuture class GenerationTaskSpigot( private val plugin: Chunkmaster, override val world: World, diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/TaskEntry.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/TaskEntry.kt similarity index 72% rename from src/main/kotlin/net/trivernis/chunkmaster/lib/TaskEntry.kt rename to src/main/kotlin/net/trivernis/chunkmaster/lib/generation/TaskEntry.kt index 4307646..f0de0dc 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/TaskEntry.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/TaskEntry.kt @@ -1,4 +1,4 @@ -package net.trivernis.chunkmaster.lib +package net.trivernis.chunkmaster.lib.generation import org.bukkit.scheduler.BukkitTask