Add option to pass the world name for cancel

- Add the option to pass the world name to chm cancel to cancel
generation tasks
- Fix #46 by adding additional error handling
release/1.0
trivernis 4 years ago
parent fd6b1e9190
commit 29d0f8991e

@ -22,7 +22,7 @@ idea {
} }
group "net.trivernis" group "net.trivernis"
version "0.16-beta" version "1.0"
sourceCompatibility = 1.8 sourceCompatibility = 1.8

@ -30,14 +30,21 @@ class CmdCancel(private val chunkmaster: Chunkmaster): Subcommand {
* Cancels the generation task if it exists. * Cancels the generation task if it exists.
*/ */
override fun execute(sender: CommandSender, args: List<String>): Boolean { override fun execute(sender: CommandSender, args: List<String>): Boolean {
return if (args.isNotEmpty() && args[0].toIntOrNull() != null) { return if (args.isNotEmpty()) {
if (chunkmaster.generationManager.removeTask(args[0].toInt())) { val index = if (args[0].toIntOrNull() != null) {
sender.sendMessage(chunkmaster.langManager.getLocalized("TASK_CANCELED", args[0])) args[0].toInt()
} else {
chunkmaster.generationManager.tasks.find { it.generationTask.world.name == args[0] }?.id
}
if (index != null && chunkmaster.generationManager.removeTask(index)) {
sender.sendMessage(chunkmaster.langManager.getLocalized("TASK_CANCELED", index))
true true
} else { } else {
sender.sendMessage(chunkmaster.langManager.getLocalized("TASK_NOT_FOUND", args[0])) sender.sendMessage(chunkmaster.langManager.getLocalized("TASK_NOT_FOUND", args[0]))
false false
} }
} else { } else {
sender.sendMessage(chunkmaster.langManager.getLocalized("TASK_ID_REQUIRED")); sender.sendMessage(chunkmaster.langManager.getLocalized("TASK_ID_REQUIRED"));
false false

@ -5,12 +5,13 @@ import net.trivernis.chunkmaster.lib.dynmap.*
import net.trivernis.chunkmaster.lib.shapes.Shape import net.trivernis.chunkmaster.lib.shapes.Shape
import org.bukkit.Chunk import org.bukkit.Chunk
import org.bukkit.World import org.bukkit.World
import java.lang.Exception
/** /**
* Interface for generation tasks. * Interface for generation tasks.
*/ */
abstract class GenerationTask( abstract class GenerationTask(
plugin: Chunkmaster, private val plugin: Chunkmaster,
startChunk: ChunkCoordinates, startChunk: ChunkCoordinates,
val shape: Shape val shape: Shape
) : ) :
@ -69,7 +70,11 @@ abstract class GenerationTask(
protected fun unloadLoadedChunks() { protected fun unloadLoadedChunks() {
for (chunk in loadedChunks) { for (chunk in loadedChunks) {
if (chunk.isLoaded) { if (chunk.isLoaded) {
chunk.unload(true) try {
chunk.unload(true)
} catch (e: Exception) {
plugin.logger.severe(e.toString())
}
} }
if (dynmapIntegration) { if (dynmapIntegration) {
dynmap?.triggerRenderOfVolume(chunk.getBlock(0, 0, 0).location, chunk.getBlock(15, 255, 15).location) dynmap?.triggerRenderOfVolume(chunk.getBlock(0, 0, 0).location, chunk.getBlock(15, 255, 15).location)

@ -4,6 +4,7 @@ import net.trivernis.chunkmaster.Chunkmaster
import net.trivernis.chunkmaster.lib.shapes.Shape import net.trivernis.chunkmaster.lib.shapes.Shape
import org.bukkit.Chunk import org.bukkit.Chunk
import org.bukkit.World import org.bukkit.World
import java.lang.Exception
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
class GenerationTaskPaper( class GenerationTaskPaper(
@ -92,7 +93,11 @@ class GenerationTaskPaper(
} }
for (chunk in loadedChunks) { for (chunk in loadedChunks) {
if (chunk.isLoaded) { if (chunk.isLoaded) {
chunk.unload(true) try {
chunk.unload(true);
} catch (e: Exception){
plugin.logger.severe(e.toString())
}
} }
} }
} }

@ -1,6 +1,6 @@
main: net.trivernis.chunkmaster.Chunkmaster main: net.trivernis.chunkmaster.Chunkmaster
name: Chunkmaster name: Chunkmaster
version: '0.16-beta' version: '1.0'
description: Chunk commands plugin. description: Chunk commands plugin.
author: Trivernis author: Trivernis
website: trivernis.net website: trivernis.net

Loading…
Cancel
Save