|
|
|
@ -12,6 +12,13 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
|
|
|
|
|
val tasks: HashSet<RunningTaskEntry> = HashSet()
|
|
|
|
|
val pausedTasks: HashSet<PausedTaskEntry> = HashSet()
|
|
|
|
|
val allTasks: HashSet<TaskEntry>
|
|
|
|
|
get() {
|
|
|
|
|
val all = HashSet<TaskEntry>()
|
|
|
|
|
all.addAll(pausedTasks)
|
|
|
|
|
all.addAll(tasks)
|
|
|
|
|
return all
|
|
|
|
|
}
|
|
|
|
|
var paused = false
|
|
|
|
|
private set
|
|
|
|
|
|
|
|
|
@ -19,6 +26,8 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
* Adds a generation task
|
|
|
|
|
*/
|
|
|
|
|
fun addTask(world: World, stopAfter: Int = -1): Int {
|
|
|
|
|
val foundTask = allTasks.find { it.generationTask.world == world }
|
|
|
|
|
if (foundTask == null) {
|
|
|
|
|
val centerChunk = world.getChunkAt(world.spawnLocation)
|
|
|
|
|
val generationTask = createGenerationTask(world, centerChunk, centerChunk, stopAfter)
|
|
|
|
|
|
|
|
|
@ -45,6 +54,11 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
insertStatement.close()
|
|
|
|
|
getIdStatement.close()
|
|
|
|
|
|
|
|
|
|
generationTask.onEndReached {
|
|
|
|
|
server.consoleSender.sendMessage("Task #${id} finished after ${generationTask.count} chunks.")
|
|
|
|
|
removeTask(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!paused) {
|
|
|
|
|
val task = server.scheduler.runTaskTimer(chunkmaster, generationTask, 10,
|
|
|
|
|
chunkmaster.config.getLong("generation.period"))
|
|
|
|
@ -54,6 +68,9 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id
|
|
|
|
|
} else {
|
|
|
|
|
return foundTask.id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -66,6 +83,10 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
val task = server.scheduler.runTaskTimer(chunkmaster, generationTask, 10,
|
|
|
|
|
chunkmaster.config.getLong("generation.period"))
|
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
|
|
generationTask.onEndReached {
|
|
|
|
|
server.consoleSender.sendMessage("Task #${id} finished after ${generationTask.count} chunks.")
|
|
|
|
|
removeTask(id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -201,11 +222,6 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
|
updateStatement.setInt(3, task.id)
|
|
|
|
|
updateStatement.execute()
|
|
|
|
|
updateStatement.close()
|
|
|
|
|
|
|
|
|
|
if (genTask.endReached) { // remove the task if it is finished after the progress has been saved
|
|
|
|
|
server.consoleSender.sendMessage("Task #${task.id} finished after ${genTask.count} chunks.")
|
|
|
|
|
removeTask(task.id)
|
|
|
|
|
}
|
|
|
|
|
} catch (error: Exception) {
|
|
|
|
|
server.consoleSender.sendMessage("Exception when saving task progress ${error.message}")
|
|
|
|
|
}
|
|
|
|
|