From bdac496ce2914ef0e79a7a6970c5961c5025472e Mon Sep 17 00:00:00 2001 From: Trivernis Date: Tue, 11 Feb 2020 12:26:38 +0100 Subject: [PATCH] Fix unique world sql error Fix error thrown by unique constrain for the world name in the sql table. The error occurs because the data from the database is loaded lazily after several seconds. If a task was started before that it wouldn't be checked against the existing tasks since they haven't been loaded yet. Fixed by loading the tasks if none exists when the generate command is invoked. --- .../chunkmaster/lib/generation/GenerationManager.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt index fffa129..830db4d 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt @@ -12,6 +12,12 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server val pausedTasks: HashSet = HashSet() val allTasks: HashSet get() { + if (this.tasks.isEmpty() && this.pausedTasks.isEmpty()) { + this.startAll() + if (!server.onlinePlayers.isEmpty()) { + this.pauseAll() + } + } val all = HashSet() all.addAll(pausedTasks) all.addAll(tasks) @@ -141,8 +147,9 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server saveProgress() // save progress every 30 seconds }, 600, 600) server.scheduler.runTaskLater(chunkmaster, Runnable { - if (server.onlinePlayers.isEmpty()) { - startAll() // run startAll after 10 seconds if empty + this.startAll() + if (!server.onlinePlayers.isEmpty()) { + this.pauseAll() } }, 600) }