|
|
|
@ -31,10 +31,12 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
val centerChunk = world.getChunkAt(world.spawnLocation)
|
|
|
|
|
val generationTask = createGenerationTask(world, centerChunk, centerChunk, stopAfter)
|
|
|
|
|
|
|
|
|
|
val insertStatement = chunkmaster.sqliteConnection.prepareStatement("""
|
|
|
|
|
val insertStatement = chunkmaster.sqliteConnection.prepareStatement(
|
|
|
|
|
"""
|
|
|
|
|
INSERT INTO generation_tasks (center_x, center_z, last_x, last_z, world, stop_after)
|
|
|
|
|
values (?, ?, ?, ?, ?, ?)
|
|
|
|
|
""")
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
insertStatement.setInt(1, centerChunk.x)
|
|
|
|
|
insertStatement.setInt(2, centerChunk.z)
|
|
|
|
|
insertStatement.setInt(3, centerChunk.x)
|
|
|
|
@ -43,9 +45,11 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
insertStatement.setInt(6, stopAfter)
|
|
|
|
|
insertStatement.execute()
|
|
|
|
|
|
|
|
|
|
val getIdStatement = chunkmaster.sqliteConnection.prepareStatement("""
|
|
|
|
|
val getIdStatement = chunkmaster.sqliteConnection.prepareStatement(
|
|
|
|
|
"""
|
|
|
|
|
SELECT id FROM generation_tasks ORDER BY id DESC LIMIT 1
|
|
|
|
|
""".trimIndent())
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
)
|
|
|
|
|
getIdStatement.execute()
|
|
|
|
|
val result = getIdStatement.resultSet
|
|
|
|
|
result.next()
|
|
|
|
@ -60,8 +64,10 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!paused) {
|
|
|
|
|
val task = server.scheduler.runTaskTimer(chunkmaster, generationTask, 10,
|
|
|
|
|
chunkmaster.config.getLong("generation.period"))
|
|
|
|
|
val task = server.scheduler.runTaskTimer(
|
|
|
|
|
chunkmaster, generationTask, 200, // 10 sec delay
|
|
|
|
|
chunkmaster.config.getLong("generation.period")
|
|
|
|
|
)
|
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
|
|
} else {
|
|
|
|
|
pausedTasks.add(PausedTaskEntry(id, generationTask))
|
|
|
|
@ -80,8 +86,10 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
if (!paused) {
|
|
|
|
|
chunkmaster.logger.info("Resuming chunk generation task for world \"${world.name}\"")
|
|
|
|
|
val generationTask = createGenerationTask(world, center, last, stopAfter)
|
|
|
|
|
val task = server.scheduler.runTaskTimer(chunkmaster, generationTask, 10,
|
|
|
|
|
chunkmaster.config.getLong("generation.period"))
|
|
|
|
|
val task = server.scheduler.runTaskTimer(
|
|
|
|
|
chunkmaster, generationTask, 200, // 10 sec delay
|
|
|
|
|
chunkmaster.config.getLong("generation.period")
|
|
|
|
|
)
|
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
|
|
generationTask.onEndReached {
|
|
|
|
|
server.consoleSender.sendMessage("Task #${id} finished after ${generationTask.count} chunks.")
|
|
|
|
@ -95,15 +103,17 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
*/
|
|
|
|
|
fun removeTask(id: Int): Boolean {
|
|
|
|
|
val taskEntry: TaskEntry? = if (this.paused) {
|
|
|
|
|
this.pausedTasks.find {it.id == id}
|
|
|
|
|
this.pausedTasks.find { it.id == id }
|
|
|
|
|
} else {
|
|
|
|
|
this.tasks.find {it.id == id}
|
|
|
|
|
this.tasks.find { it.id == id }
|
|
|
|
|
}
|
|
|
|
|
if (taskEntry != null) {
|
|
|
|
|
taskEntry.cancel()
|
|
|
|
|
val deleteTask = chunkmaster.sqliteConnection.prepareStatement("""
|
|
|
|
|
val deleteTask = chunkmaster.sqliteConnection.prepareStatement(
|
|
|
|
|
"""
|
|
|
|
|
DELETE FROM generation_tasks WHERE id = ?;
|
|
|
|
|
""".trimIndent())
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
)
|
|
|
|
|
deleteTask.setInt(1, taskEntry.id)
|
|
|
|
|
deleteTask.execute()
|
|
|
|
|
deleteTask.close()
|
|
|
|
@ -162,15 +172,13 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
val res = savedTasksStatement.resultSet
|
|
|
|
|
while (res.next()) {
|
|
|
|
|
try {
|
|
|
|
|
if (res.getBoolean("autostart")) {
|
|
|
|
|
val id = res.getInt("id")
|
|
|
|
|
val world = server.getWorld(res.getString("world"))
|
|
|
|
|
val center = world!!.getChunkAt(res.getInt("center_x"), res.getInt("center_z"))
|
|
|
|
|
val last = world.getChunkAt(res.getInt("last_x"), res.getInt("last_z"))
|
|
|
|
|
val stopAfter = res.getInt("stop_after")
|
|
|
|
|
if (this.tasks.find {it.id == id} == null) {
|
|
|
|
|
resumeTask(world, center, last, id, stopAfter)
|
|
|
|
|
}
|
|
|
|
|
val id = res.getInt("id")
|
|
|
|
|
val world = server.getWorld(res.getString("world"))
|
|
|
|
|
val center = world!!.getChunkAt(res.getInt("center_x"), res.getInt("center_z"))
|
|
|
|
|
val last = world.getChunkAt(res.getInt("last_x"), res.getInt("last_z"))
|
|
|
|
|
val stopAfter = res.getInt("stop_after")
|
|
|
|
|
if (this.tasks.find { it.id == id } == null) {
|
|
|
|
|
resumeTask(world, center, last, id, stopAfter)
|
|
|
|
|
}
|
|
|
|
|
} catch (error: NullPointerException) {
|
|
|
|
|
server.consoleSender.sendMessage("Failed to load Task ${res.getInt("id")}.")
|
|
|
|
@ -209,15 +217,19 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
for (task in tasks) {
|
|
|
|
|
try {
|
|
|
|
|
val genTask = task.generationTask
|
|
|
|
|
server.consoleSender.sendMessage("""Task #${task.id} running for "${genTask.world.name}".
|
|
|
|
|
server.consoleSender.sendMessage(
|
|
|
|
|
"""Task #${task.id} running for "${genTask.world.name}".
|
|
|
|
|
|Progress ${task.generationTask.count} chunks
|
|
|
|
|
|${if (task.generationTask.stopAfter > 0)"(${(task.generationTask.count.toDouble()/
|
|
|
|
|
task.generationTask.stopAfter.toDouble())*100}%)" else ""}.
|
|
|
|
|
|Last Chunk: ${genTask.lastChunk.x}, ${genTask.lastChunk.z}""".trimMargin("|").replace('\n', ' '))
|
|
|
|
|
val updateStatement = chunkmaster.sqliteConnection.prepareStatement("""
|
|
|
|
|
|${if (task.generationTask.stopAfter > 0) "(${(task.generationTask.count.toDouble() /
|
|
|
|
|
task.generationTask.stopAfter.toDouble()) * 100}%)" else ""}.
|
|
|
|
|
|Last Chunk: ${genTask.lastChunk.x}, ${genTask.lastChunk.z}""".trimMargin("|").replace('\n', ' ')
|
|
|
|
|
)
|
|
|
|
|
val updateStatement = chunkmaster.sqliteConnection.prepareStatement(
|
|
|
|
|
"""
|
|
|
|
|
UPDATE generation_tasks SET last_x = ?, last_z = ?
|
|
|
|
|
WHERE id = ?
|
|
|
|
|
""".trimIndent())
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
)
|
|
|
|
|
updateStatement.setInt(1, genTask.lastChunk.x)
|
|
|
|
|
updateStatement.setInt(2, genTask.lastChunk.z)
|
|
|
|
|
updateStatement.setInt(3, task.id)
|
|
|
|
@ -236,7 +248,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
private fun createGenerationTask(world: World, center: Chunk, start: Chunk, stopAfter: Int): GenerationTask {
|
|
|
|
|
return if (PaperLib.isPaper()) {
|
|
|
|
|
GenerationTaskPaper(chunkmaster, world, center, start, stopAfter)
|
|
|
|
|
} else {
|
|
|
|
|
} else {
|
|
|
|
|
GenerationTaskSpigot(chunkmaster, world, center, start, stopAfter)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|