|
|
@ -28,13 +28,15 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
fun addTask(world: World, stopAfter: Int = -1): Int {
|
|
|
|
fun addTask(world: World, stopAfter: Int = -1): Int {
|
|
|
|
val foundTask = allTasks.find { it.generationTask.world == world }
|
|
|
|
val foundTask = allTasks.find { it.generationTask.world == world }
|
|
|
|
if (foundTask == null) {
|
|
|
|
if (foundTask == null) {
|
|
|
|
val centerChunk = world.getChunkAt(world.spawnLocation)
|
|
|
|
val centerChunk = ChunkCoordinates(world.spawnLocation.chunk.x, world.spawnLocation.chunk.z)
|
|
|
|
val generationTask = createGenerationTask(world, centerChunk, centerChunk, stopAfter)
|
|
|
|
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)
|
|
|
|
INSERT INTO generation_tasks (center_x, center_z, last_x, last_z, world, stop_after)
|
|
|
|
values (?, ?, ?, ?, ?, ?)
|
|
|
|
values (?, ?, ?, ?, ?, ?)
|
|
|
|
""")
|
|
|
|
"""
|
|
|
|
|
|
|
|
)
|
|
|
|
insertStatement.setInt(1, centerChunk.x)
|
|
|
|
insertStatement.setInt(1, centerChunk.x)
|
|
|
|
insertStatement.setInt(2, centerChunk.z)
|
|
|
|
insertStatement.setInt(2, centerChunk.z)
|
|
|
|
insertStatement.setInt(3, centerChunk.x)
|
|
|
|
insertStatement.setInt(3, centerChunk.x)
|
|
|
@ -43,9 +45,11 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
insertStatement.setInt(6, stopAfter)
|
|
|
|
insertStatement.setInt(6, stopAfter)
|
|
|
|
insertStatement.execute()
|
|
|
|
insertStatement.execute()
|
|
|
|
|
|
|
|
|
|
|
|
val getIdStatement = chunkmaster.sqliteConnection.prepareStatement("""
|
|
|
|
val getIdStatement = chunkmaster.sqliteConnection.prepareStatement(
|
|
|
|
|
|
|
|
"""
|
|
|
|
SELECT id FROM generation_tasks ORDER BY id DESC LIMIT 1
|
|
|
|
SELECT id FROM generation_tasks ORDER BY id DESC LIMIT 1
|
|
|
|
""".trimIndent())
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
)
|
|
|
|
getIdStatement.execute()
|
|
|
|
getIdStatement.execute()
|
|
|
|
val result = getIdStatement.resultSet
|
|
|
|
val result = getIdStatement.resultSet
|
|
|
|
result.next()
|
|
|
|
result.next()
|
|
|
@ -55,13 +59,15 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
getIdStatement.close()
|
|
|
|
getIdStatement.close()
|
|
|
|
|
|
|
|
|
|
|
|
generationTask.onEndReached {
|
|
|
|
generationTask.onEndReached {
|
|
|
|
server.consoleSender.sendMessage("Task #${id} finished after ${generationTask.count} chunks.")
|
|
|
|
chunkmaster.logger.info("Task #${id} finished after ${generationTask.count} chunks.")
|
|
|
|
removeTask(id)
|
|
|
|
removeTask(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!paused) {
|
|
|
|
if (!paused) {
|
|
|
|
val task = server.scheduler.runTaskTimer(chunkmaster, generationTask, 10,
|
|
|
|
val task = server.scheduler.runTaskTimer(
|
|
|
|
chunkmaster.config.getLong("generation.period"))
|
|
|
|
chunkmaster, generationTask, 200, // 10 sec delay
|
|
|
|
|
|
|
|
chunkmaster.config.getLong("generation.period")
|
|
|
|
|
|
|
|
)
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
pausedTasks.add(PausedTaskEntry(id, generationTask))
|
|
|
|
pausedTasks.add(PausedTaskEntry(id, generationTask))
|
|
|
@ -76,15 +82,23 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Resumes a generation task
|
|
|
|
* Resumes a generation task
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private fun resumeTask(world: World, center: Chunk, last: Chunk, id: Int, stopAfter: Int = -1) {
|
|
|
|
private fun resumeTask(
|
|
|
|
|
|
|
|
world: World,
|
|
|
|
|
|
|
|
center: ChunkCoordinates,
|
|
|
|
|
|
|
|
last: ChunkCoordinates,
|
|
|
|
|
|
|
|
id: Int,
|
|
|
|
|
|
|
|
stopAfter: Int = -1
|
|
|
|
|
|
|
|
) {
|
|
|
|
if (!paused) {
|
|
|
|
if (!paused) {
|
|
|
|
chunkmaster.logger.info("Resuming chunk generation task for world \"${world.name}\"")
|
|
|
|
chunkmaster.logger.info("Resuming chunk generation task for world \"${world.name}\"")
|
|
|
|
val generationTask = createGenerationTask(world, center, last, stopAfter)
|
|
|
|
val generationTask = createGenerationTask(world, center, last, stopAfter)
|
|
|
|
val task = server.scheduler.runTaskTimer(chunkmaster, generationTask, 10,
|
|
|
|
val task = server.scheduler.runTaskTimer(
|
|
|
|
chunkmaster.config.getLong("generation.period"))
|
|
|
|
chunkmaster, generationTask, 200, // 10 sec delay
|
|
|
|
|
|
|
|
chunkmaster.config.getLong("generation.period")
|
|
|
|
|
|
|
|
)
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
|
tasks.add(RunningTaskEntry(id, task, generationTask))
|
|
|
|
generationTask.onEndReached {
|
|
|
|
generationTask.onEndReached {
|
|
|
|
server.consoleSender.sendMessage("Task #${id} finished after ${generationTask.count} chunks.")
|
|
|
|
chunkmaster.logger.info("Task #${id} finished after ${generationTask.count} chunks.")
|
|
|
|
removeTask(id)
|
|
|
|
removeTask(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,9 +115,11 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (taskEntry != null) {
|
|
|
|
if (taskEntry != null) {
|
|
|
|
taskEntry.cancel()
|
|
|
|
taskEntry.cancel()
|
|
|
|
val deleteTask = chunkmaster.sqliteConnection.prepareStatement("""
|
|
|
|
val deleteTask = chunkmaster.sqliteConnection.prepareStatement(
|
|
|
|
|
|
|
|
"""
|
|
|
|
DELETE FROM generation_tasks WHERE id = ?;
|
|
|
|
DELETE FROM generation_tasks WHERE id = ?;
|
|
|
|
""".trimIndent())
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
)
|
|
|
|
deleteTask.setInt(1, taskEntry.id)
|
|
|
|
deleteTask.setInt(1, taskEntry.id)
|
|
|
|
deleteTask.execute()
|
|
|
|
deleteTask.execute()
|
|
|
|
deleteTask.close()
|
|
|
|
deleteTask.close()
|
|
|
@ -133,7 +149,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
if (server.onlinePlayers.isEmpty()) {
|
|
|
|
if (server.onlinePlayers.isEmpty()) {
|
|
|
|
startAll() // run startAll after 10 seconds if empty
|
|
|
|
startAll() // run startAll after 10 seconds if empty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 200)
|
|
|
|
}, 600)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -157,29 +173,28 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
* Starts all generation tasks.
|
|
|
|
* Starts all generation tasks.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
fun startAll() {
|
|
|
|
fun startAll() {
|
|
|
|
chunkmaster.logger.info("Loading saved chunk generation tasks...")
|
|
|
|
|
|
|
|
val savedTasksStatement = chunkmaster.sqliteConnection.prepareStatement("SELECT * FROM generation_tasks")
|
|
|
|
val savedTasksStatement = chunkmaster.sqliteConnection.prepareStatement("SELECT * FROM generation_tasks")
|
|
|
|
savedTasksStatement.execute()
|
|
|
|
savedTasksStatement.execute()
|
|
|
|
val res = savedTasksStatement.resultSet
|
|
|
|
val res = savedTasksStatement.resultSet
|
|
|
|
while (res.next()) {
|
|
|
|
while (res.next()) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (res.getBoolean("autostart")) {
|
|
|
|
|
|
|
|
val id = res.getInt("id")
|
|
|
|
val id = res.getInt("id")
|
|
|
|
val world = server.getWorld(res.getString("world"))
|
|
|
|
val world = server.getWorld(res.getString("world"))
|
|
|
|
val center = world!!.getChunkAt(res.getInt("center_x"), res.getInt("center_z"))
|
|
|
|
val center = ChunkCoordinates(res.getInt("center_x"), res.getInt("center_z"))
|
|
|
|
val last = world.getChunkAt(res.getInt("last_x"), res.getInt("last_z"))
|
|
|
|
val last = ChunkCoordinates(res.getInt("last_x"), res.getInt("last_z"))
|
|
|
|
val stopAfter = res.getInt("stop_after")
|
|
|
|
val stopAfter = res.getInt("stop_after")
|
|
|
|
if (this.tasks.find { it.id == id } == null) {
|
|
|
|
if (this.tasks.find { it.id == id } == null) {
|
|
|
|
resumeTask(world, center, last, id, stopAfter)
|
|
|
|
resumeTask(world!!, center, last, id, stopAfter)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error: NullPointerException) {
|
|
|
|
} catch (error: NullPointerException) {
|
|
|
|
server.consoleSender.sendMessage("Failed to load Task ${res.getInt("id")}.")
|
|
|
|
chunkmaster.logger.severe("Failed to load Task ${res.getInt("id")}.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
savedTasksStatement.close()
|
|
|
|
savedTasksStatement.close()
|
|
|
|
|
|
|
|
if (tasks.isNotEmpty()) {
|
|
|
|
chunkmaster.logger.info("${tasks.size} saved tasks loaded.")
|
|
|
|
chunkmaster.logger.info("${tasks.size} saved tasks loaded.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Pauses all tasks
|
|
|
|
* Pauses all tasks
|
|
|
@ -208,22 +223,27 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
for (task in tasks) {
|
|
|
|
for (task in tasks) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
val genTask = task.generationTask
|
|
|
|
val genTask = task.generationTask
|
|
|
|
server.consoleSender.sendMessage("""Task #${task.id} running for "${genTask.world.name}".
|
|
|
|
chunkmaster.logger.info(
|
|
|
|
|
|
|
|
"""Task #${task.id} running for "${genTask.world.name}".
|
|
|
|
|Progress ${task.generationTask.count} chunks
|
|
|
|
|Progress ${task.generationTask.count} chunks
|
|
|
|
|${if (task.generationTask.stopAfter > 0)"(${(task.generationTask.count.toDouble()/
|
|
|
|
|${if (task.generationTask.stopAfter > 0) "(${"%.2f".format((task.generationTask.count.toDouble() /
|
|
|
|
task.generationTask.stopAfter.toDouble())*100}%)" else ""}.
|
|
|
|
task.generationTask.stopAfter.toDouble()) * 100)}%)" else ""}.
|
|
|
|
|Last Chunk: ${genTask.lastChunk.x}, ${genTask.lastChunk.z}""".trimMargin("|").replace('\n', ' '))
|
|
|
|
| Speed: ${"%.1f".format(task.generationSpeed)} chunks/sec,
|
|
|
|
val updateStatement = chunkmaster.sqliteConnection.prepareStatement("""
|
|
|
|
|Last Chunk: ${genTask.lastChunk.x}, ${genTask.lastChunk.z}""".trimMargin("|").replace('\n', ' ')
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
val updateStatement = chunkmaster.sqliteConnection.prepareStatement(
|
|
|
|
|
|
|
|
"""
|
|
|
|
UPDATE generation_tasks SET last_x = ?, last_z = ?
|
|
|
|
UPDATE generation_tasks SET last_x = ?, last_z = ?
|
|
|
|
WHERE id = ?
|
|
|
|
WHERE id = ?
|
|
|
|
""".trimIndent())
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
)
|
|
|
|
updateStatement.setInt(1, genTask.lastChunk.x)
|
|
|
|
updateStatement.setInt(1, genTask.lastChunk.x)
|
|
|
|
updateStatement.setInt(2, genTask.lastChunk.z)
|
|
|
|
updateStatement.setInt(2, genTask.lastChunk.z)
|
|
|
|
updateStatement.setInt(3, task.id)
|
|
|
|
updateStatement.setInt(3, task.id)
|
|
|
|
updateStatement.execute()
|
|
|
|
updateStatement.execute()
|
|
|
|
updateStatement.close()
|
|
|
|
updateStatement.close()
|
|
|
|
} catch (error: Exception) {
|
|
|
|
} catch (error: Exception) {
|
|
|
|
server.consoleSender.sendMessage("Exception when saving task progress ${error.message}")
|
|
|
|
chunkmaster.logger.warning("Exception when saving task progress ${error.message}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -232,7 +252,12 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
|
|
|
|
* Creates a new generation task. This method is used to create a task depending
|
|
|
|
* Creates a new generation task. This method is used to create a task depending
|
|
|
|
* on the server type (Paper/Spigot).
|
|
|
|
* on the server type (Paper/Spigot).
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private fun createGenerationTask(world: World, center: Chunk, start: Chunk, stopAfter: Int): GenerationTask {
|
|
|
|
private fun createGenerationTask(
|
|
|
|
|
|
|
|
world: World,
|
|
|
|
|
|
|
|
center: ChunkCoordinates,
|
|
|
|
|
|
|
|
start: ChunkCoordinates,
|
|
|
|
|
|
|
|
stopAfter: Int
|
|
|
|
|
|
|
|
): GenerationTask {
|
|
|
|
return if (PaperLib.isPaper()) {
|
|
|
|
return if (PaperLib.isPaper()) {
|
|
|
|
GenerationTaskPaper(chunkmaster, world, center, start, stopAfter)
|
|
|
|
GenerationTaskPaper(chunkmaster, world, center, start, stopAfter)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|