diff --git a/build.gradle b/build.gradle index 9930870..581da97 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ idea { } group "net.trivernis" -version "0.10-beta" +version "0.11-beta" sourceCompatibility = 1.8 @@ -31,9 +31,6 @@ repositories { maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots" } - maven { - url 'https://papermc.io/repo/repository/maven-public/' - } maven { url 'https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc' } @@ -41,6 +38,10 @@ repositories { name 'papermc' url 'https://papermc.io/repo/repository/maven-public/' } + maven { + name 'CodeMc' + url 'https://repo.codemc.org/repository/maven-public' + } } dependencies { @@ -50,11 +51,15 @@ dependencies { compileOnly "org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT" compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0' compile "io.papermc:paperlib:1.0.2" + compile "org.bstats:bstats-bukkit:1.5" } apply plugin: "com.github.johnrengelman.shadow" +apply plugin: 'java' + shadowJar { relocate 'io.papermc.lib', 'net.trivernis.chunkmaster.paperlib' + relocate 'org.bstats', 'net.trivernis.chunkmaster.bstats' } jar { diff --git a/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt b/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt index 117bb10..6d5ab8b 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt @@ -4,6 +4,7 @@ import io.papermc.lib.PaperLib import net.trivernis.chunkmaster.commands.* import net.trivernis.chunkmaster.lib.generation.GenerationManager import net.trivernis.chunkmaster.lib.SqlUpdateManager +import org.bstats.bukkit.Metrics import org.bukkit.plugin.java.JavaPlugin import org.bukkit.scheduler.BukkitTask import java.lang.Exception @@ -24,6 +25,9 @@ class Chunkmaster: JavaPlugin() { override fun onEnable() { PaperLib.suggestPaper(this) configure() + + val metrics = Metrics(this) + initDatabase() generationManager = GenerationManager(this, server) generationManager.init() diff --git a/src/main/kotlin/net/trivernis/chunkmaster/ChunkmasterEvents.kt b/src/main/kotlin/net/trivernis/chunkmaster/ChunkmasterEvents.kt index b93c651..60328f5 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/ChunkmasterEvents.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/ChunkmasterEvents.kt @@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerQuitEvent class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server: Server) : Listener { private val pauseOnJoin = chunkmaster.config.getBoolean("generation.pause-on-join") + private var playerPaused = false /** * Autostart generation tasks @@ -19,9 +20,14 @@ class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server if (server.onlinePlayers.size == 1 && server.onlinePlayers.contains(event.player) || server.onlinePlayers.isEmpty() ) { - if (!chunkmaster.generationManager.paused) { - chunkmaster.generationManager.startAll() - chunkmaster.logger.info("Server is empty. Starting chunk generation tasks.") + if (!playerPaused) { + chunkmaster.generationManager.resumeAll() + chunkmaster.logger.info("Server is empty. Resuming chunk generation tasks.") + } else if (chunkmaster.generationManager.paused){ + chunkmaster.logger.info("Generation was manually paused. Not resuming automatically.") + playerPaused = chunkmaster.generationManager.paused + } else { + chunkmaster.logger.info("Generation tasks are already running.") } } } @@ -34,8 +40,9 @@ class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server fun onPlayerJoin(event: PlayerJoinEvent) { if (pauseOnJoin) { if (server.onlinePlayers.size == 1 || server.onlinePlayers.isEmpty()) { - chunkmaster.generationManager.stopAll() - chunkmaster.logger.info("Stopping generation tasks because of player join.") + playerPaused = chunkmaster.generationManager.paused + chunkmaster.generationManager.pauseAll() + chunkmaster.logger.info("Pausing generation tasks because of player join.") } } } diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdCancel.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdCancel.kt index 80daf60..052ee60 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdCancel.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdCancel.kt @@ -4,11 +4,31 @@ import net.md_5.bungee.api.ChatColor import net.md_5.bungee.api.chat.ComponentBuilder import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.lib.Subcommand +import net.trivernis.chunkmaster.lib.generation.TaskEntry +import org.bukkit.command.Command import org.bukkit.command.CommandSender class CmdCancel(private val chunkmaster: Chunkmaster): Subcommand { override val name = "cancel" + /** + * TabComplete for subcommand cancel. + */ + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: List + ): MutableList { + val genManager = chunkmaster.generationManager + val allTasks = genManager.allTasks + return allTasks.filter {it.id.toString().indexOf(args[0]) == 0} + .map { it.id.toString() }.toMutableList() + } + + /** + * Cancels the generation task if it exists. + */ override fun execute(sender: CommandSender, args: List): Boolean { return if (args.isNotEmpty() && args[0].toIntOrNull() != null) { if (chunkmaster.generationManager.removeTask(args[0].toInt())) { diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdGenerate.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdGenerate.kt index 4ef2a15..b9a5431 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdGenerate.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdGenerate.kt @@ -4,12 +4,32 @@ import net.md_5.bungee.api.ChatColor import net.md_5.bungee.api.chat.ComponentBuilder import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.lib.Subcommand +import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.entity.Player class CmdGenerate(private val chunkmaster: Chunkmaster): Subcommand { override val name = "generate" + /** + * TabComplete for generate command. + */ + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: List + ): MutableList { + if (args.size == 1) { + return sender.server.worlds.filter { it.name.indexOf(args[0]) == 0 } + .map {it.name}.toMutableList() + } + return emptyList().toMutableList() + } + + /** + * Creates a new generation task for the world and chunk count. + */ override fun execute(sender: CommandSender, args: List): Boolean { var worldName = "" var stopAfter = -1 @@ -39,17 +59,21 @@ class CmdGenerate(private val chunkmaster: Chunkmaster): Subcommand { } } val world = chunkmaster.server.getWorld(worldName) - return if (world != null) { + val allTasks = chunkmaster.generationManager.allTasks + return if (world != null && (allTasks.find { it.generationTask.world == world }) == null) { chunkmaster.generationManager.addTask(world, stopAfter) sender.spigot().sendMessage(*ComponentBuilder("Generation task for world ").color(ChatColor.BLUE) .append(worldName).color(ChatColor.GREEN).append(" until ").color(ChatColor.BLUE) .append(if (stopAfter > 0) "$stopAfter chunks" else "WorldBorder").color(ChatColor.GREEN) .append(" successfully created").color(ChatColor.BLUE).create()) true - } else { + } else if (world == null){ sender.spigot().sendMessage(*ComponentBuilder("World ").color(ChatColor.RED) .append(worldName).color(ChatColor.GREEN).append(" not found!").color(ChatColor.RED).create()) false + } else { + sender.spigot().sendMessage(*ComponentBuilder("Task already exists!").color(ChatColor.RED).create()) + return false } } } \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdList.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdList.kt index 3e5cca8..00703b7 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdList.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdList.kt @@ -4,21 +4,57 @@ import net.md_5.bungee.api.ChatColor import net.md_5.bungee.api.chat.ComponentBuilder import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.lib.Subcommand +import org.bukkit.command.Command import org.bukkit.command.CommandSender class CmdList(private val chunkmaster: Chunkmaster): Subcommand { override val name = "list" + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: List + ): MutableList { + return emptyList().toMutableList() + } + + /** + * Lists all running or paused generation tasks. + */ override fun execute(sender: CommandSender, args: List): Boolean { val runningTasks = chunkmaster.generationManager.tasks - if (runningTasks.isEmpty()) { - sender.spigot().sendMessage(*ComponentBuilder("There are no running generation tasks.") + val pausedTasks = chunkmaster.generationManager.pausedTasks + + if (runningTasks.isEmpty() && pausedTasks.isEmpty()) { + sender.spigot().sendMessage(*ComponentBuilder("There are no generation tasks.") .color(ChatColor.BLUE).create()) + } else if (runningTasks.isEmpty()) { + val response = ComponentBuilder("Currently paused generation tasks:").color(ChatColor.WHITE).bold(true) + for (taskEntry in pausedTasks) { + val genTask = taskEntry.generationTask + response.append("\n - ").color(ChatColor.WHITE).bold(false) + response.append("#${taskEntry.id}").color(ChatColor.BLUE).append(" - ").color(ChatColor.WHITE) + response.append(genTask.world.name).color(ChatColor.GREEN).append(" - Progress: ").color(ChatColor.WHITE) + response.append("${genTask.count} chunks").color(ChatColor.BLUE) + + if (genTask.stopAfter > 0) { + response.append(" (${(genTask.count.toDouble()/genTask.stopAfter.toDouble())*100}%).") + } + } + sender.spigot().sendMessage(*response.create()) } else { - val response = ComponentBuilder("Currently running generation tasks:").color(ChatColor.WHITE) + val response = ComponentBuilder("Currently running generation tasks:").color(ChatColor.WHITE).bold(true) for (task in runningTasks) { - response.append("\n - #${task.id}: ${task.generationTask.world.name}, Progress ${task.generationTask.count}") - .color(ChatColor.BLUE) + val genTask = task.generationTask + response.append("\n - ").color(ChatColor.WHITE).bold(false) + .append("#${task.id}").color(ChatColor.BLUE).append(" - ").color(ChatColor.WHITE) + .append(genTask.world.name).color(ChatColor.GREEN).append(" - Progress: ").color(ChatColor.WHITE) + .append("${genTask.count} chunks").color(ChatColor.BLUE) + + if (genTask.stopAfter > 0) { + response.append(" (${(genTask.count.toDouble()/genTask.stopAfter.toDouble())*100}%).") + } } sender.spigot().sendMessage(*response.create()) } diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdPause.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdPause.kt index b125f68..20c8fb8 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdPause.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdPause.kt @@ -4,11 +4,21 @@ import net.md_5.bungee.api.ChatColor import net.md_5.bungee.api.chat.ComponentBuilder import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.lib.Subcommand +import org.bukkit.command.Command import org.bukkit.command.CommandSender class CmdPause(private val chunkmaster: Chunkmaster) : Subcommand { override val name: String = "pause" + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: List + ): MutableList { + return emptyList().toMutableList() + } + override fun execute(sender: CommandSender, args: List): Boolean { return if (!chunkmaster.generationManager.paused) { chunkmaster.generationManager.pauseAll() diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdResume.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdResume.kt index 72b3068..df05ea6 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdResume.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdResume.kt @@ -4,11 +4,21 @@ import net.md_5.bungee.api.ChatColor import net.md_5.bungee.api.chat.ComponentBuilder import net.trivernis.chunkmaster.Chunkmaster import net.trivernis.chunkmaster.lib.Subcommand +import org.bukkit.command.Command import org.bukkit.command.CommandSender class CmdResume(private val chunkmaster: Chunkmaster): Subcommand { override val name = "resume" + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: List + ): MutableList { + return emptyList().toMutableList() + } + override fun execute(sender: CommandSender, args: List): Boolean { return if (chunkmaster.generationManager.paused) { chunkmaster.generationManager.resumeAll() diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CommandChunkmaster.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CommandChunkmaster.kt index c59f0ac..ef313a8 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CommandChunkmaster.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CommandChunkmaster.kt @@ -23,7 +23,16 @@ class CommandChunkmaster(private val chunkmaster: Chunkmaster, private val serve */ override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array): MutableList { - return commands.keys.filter { it.indexOf(args[0]) == 0 }.toMutableList() + if (args.size == 1) { + return commands.keys.filter { it.indexOf(args[0]) == 0 }.toMutableList() + } else if (args.isNotEmpty()){ + + if (commands.containsKey(args[0])) { + val commandEntry = commands[args[0]] + return commandEntry!!.onTabComplete(sender, command, alias, args.slice(1 until args.size)) + } + } + return emptyList().toMutableList() } /** diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/Subcommand.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/Subcommand.kt index 65cb06f..7341e30 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/Subcommand.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/Subcommand.kt @@ -1,8 +1,10 @@ package net.trivernis.chunkmaster.lib +import org.bukkit.command.Command import org.bukkit.command.CommandSender interface Subcommand { val name: String fun execute(sender: CommandSender, args: List): Boolean + fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: List): MutableList } \ No newline at end of file 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 a4c615c..a7d01d4 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationManager.kt @@ -10,7 +10,15 @@ import java.lang.NullPointerException class GenerationManager(private val chunkmaster: Chunkmaster, private val server: Server) { - val tasks: HashSet = HashSet() + val tasks: HashSet = HashSet() + val pausedTasks: HashSet = HashSet() + val allTasks: HashSet + get() { + val all = HashSet() + all.addAll(pausedTasks) + all.addAll(tasks) + return all + } var paused = false private set @@ -18,39 +26,51 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server * Adds a generation task */ fun addTask(world: World, stopAfter: Int = -1): Int { - val centerChunk = world.getChunkAt(world.spawnLocation) - val generationTask = createGenerationTask(world, centerChunk, centerChunk, stopAfter) + val foundTask = allTasks.find { it.generationTask.world == world } + if (foundTask == null) { + 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) - insertStatement.setInt(4, centerChunk.z) - insertStatement.setString(5, world.name) - insertStatement.setInt(6, stopAfter) - insertStatement.execute() - - val getIdStatement = chunkmaster.sqliteConnection.prepareStatement(""" + insertStatement.setInt(1, centerChunk.x) + insertStatement.setInt(2, centerChunk.z) + insertStatement.setInt(3, centerChunk.x) + insertStatement.setInt(4, centerChunk.z) + insertStatement.setString(5, world.name) + insertStatement.setInt(6, stopAfter) + insertStatement.execute() + + val getIdStatement = chunkmaster.sqliteConnection.prepareStatement(""" SELECT id FROM generation_tasks ORDER BY id DESC LIMIT 1 """.trimIndent()) - getIdStatement.execute() - val result = getIdStatement.resultSet - result.next() - val id: Int = result.getInt("id") + getIdStatement.execute() + val result = getIdStatement.resultSet + result.next() + val id: Int = result.getInt("id") - insertStatement.close() - getIdStatement.close() + insertStatement.close() + getIdStatement.close() - if (!paused) { - val task = server.scheduler.runTaskTimer(chunkmaster, generationTask, 10, - chunkmaster.config.getLong("generation.period")) - tasks.add(TaskEntry(id, task, generationTask)) - } + 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")) + tasks.add(RunningTaskEntry(id, task, generationTask)) + } else { + pausedTasks.add(PausedTaskEntry(id, generationTask)) + } - return id + return id + } else { + return foundTask.id + } } /** @@ -62,7 +82,11 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server val generationTask = createGenerationTask(world, center, last, stopAfter) val task = server.scheduler.runTaskTimer(chunkmaster, generationTask, 10, chunkmaster.config.getLong("generation.period")) - tasks.add(TaskEntry(id, task, generationTask)) + tasks.add(RunningTaskEntry(id, task, generationTask)) + generationTask.onEndReached { + server.consoleSender.sendMessage("Task #${id} finished after ${generationTask.count} chunks.") + removeTask(id) + } } } @@ -70,18 +94,26 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server * Stops a running generation task. */ fun removeTask(id: Int): Boolean { - val taskEntry = this.tasks.find {it.id == id} + val taskEntry: TaskEntry? = if (this.paused) { + this.pausedTasks.find {it.id == id} + } else { + this.tasks.find {it.id == id} + } if (taskEntry != null) { - taskEntry.generationTask.cancel() - taskEntry.task.cancel() + taskEntry.cancel() val deleteTask = chunkmaster.sqliteConnection.prepareStatement(""" DELETE FROM generation_tasks WHERE id = ?; """.trimIndent()) deleteTask.setInt(1, taskEntry.id) deleteTask.execute() deleteTask.close() - if (taskEntry.task.isCancelled) { - tasks.remove(taskEntry) + + if (taskEntry is RunningTaskEntry) { + if (taskEntry.task.isCancelled) { + tasks.remove(taskEntry) + } + } else if (taskEntry is PausedTaskEntry) { + pausedTasks.remove(taskEntry) } return true } @@ -109,7 +141,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server */ fun stopAll() { saveProgress() - val removalSet = HashSet() + val removalSet = HashSet() for (task in tasks) { task.generationTask.cancel() task.task.cancel() @@ -154,6 +186,9 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server */ fun pauseAll() { paused = true + for (task in tasks) { + pausedTasks.add(PausedTaskEntry(task.id, task.generationTask)) + } stopAll() } @@ -162,6 +197,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server */ fun resumeAll() { paused = false + pausedTasks.clear() startAll() } @@ -174,7 +210,8 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server val genTask = task.generationTask 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 ""}. + |${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 = ? @@ -185,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}") } diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt index e8c1233..91f8575 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt @@ -23,6 +23,9 @@ abstract class GenerationTask(plugin: Chunkmaster, centerChunk: Chunk, startChun protected val msptThreshold = plugin.config.getLong("generation.mspt-pause-threshold") protected val maxLoadedChunks = plugin.config.getInt("generation.max-loaded-chunks") + protected var endReachedCallback: (() -> Unit)? = null + private set + abstract override fun run() abstract fun cancel() @@ -48,4 +51,11 @@ abstract class GenerationTask(plugin: Chunkmaster, centerChunk: Chunk, startChun protected fun borderReached(): Boolean { return !world.worldBorder.isInside(lastChunkCoords.getCenterLocation(world)) || (stopAfter in 1..count) } + + /** + * Registers end reached callback + */ + fun onEndReached(cb: () -> Unit) { + endReachedCallback = cb + } } \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskPaper.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskPaper.kt index 756d085..2a49321 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskPaper.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskPaper.kt @@ -38,6 +38,7 @@ class GenerationTaskPaper( } else if (pendingChunks.size < maxPendingChunks) { // if more than 10 chunks are pending, wait. if (borderReached()) { endReached = true + endReachedCallback?.invoke() return } @@ -73,6 +74,9 @@ class GenerationTaskPaper( } } pendingChunks.clear() + if (loadedChunks.isNotEmpty()) { + lastChunkCoords = ChunkCoordinates(loadedChunks.last().x, loadedChunks.last().z) + } for (chunk in loadedChunks) { if (chunk.isLoaded) { chunk.unload(true) diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskSpigot.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskSpigot.kt index f54f666..ea71d4d 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskSpigot.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTaskSpigot.kt @@ -33,6 +33,7 @@ class GenerationTaskSpigot( } else { if (borderReached()) { endReached = true + endReachedCallback?.invoke() return } diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/PausedTaskEntry.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/PausedTaskEntry.kt new file mode 100644 index 0000000..90b7736 --- /dev/null +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/PausedTaskEntry.kt @@ -0,0 +1,10 @@ +package net.trivernis.chunkmaster.lib.generation + +class PausedTaskEntry( + override val id: Int, + override val generationTask: GenerationTask +) : TaskEntry { + override fun cancel() { + generationTask.cancel() + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/RunningTaskEntry.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/RunningTaskEntry.kt new file mode 100644 index 0000000..a53d89a --- /dev/null +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/RunningTaskEntry.kt @@ -0,0 +1,14 @@ +package net.trivernis.chunkmaster.lib.generation + +import org.bukkit.scheduler.BukkitTask + +class RunningTaskEntry( + override val id: Int, + val task: BukkitTask, + override val generationTask: GenerationTask +) : TaskEntry { + override fun cancel() { + task.cancel() + generationTask.cancel() + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/TaskEntry.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/TaskEntry.kt index 552461b..cf6b135 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/TaskEntry.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/TaskEntry.kt @@ -2,4 +2,12 @@ package net.trivernis.chunkmaster.lib.generation import org.bukkit.scheduler.BukkitTask -data class TaskEntry(val id: Int, val task: BukkitTask, val generationTask: GenerationTask) \ No newline at end of file +/** + * Generic task entry + */ +interface TaskEntry { + val id: Int + val generationTask: GenerationTask + + fun cancel() +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 096b64a..350e596 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: net.trivernis.chunkmaster.Chunkmaster name: Chunkmaster -version: '0.10-beta' +version: '0.11-beta' description: Chunk commands plugin. author: Trivernis website: trivernis.net