Added generation list task

pull/4/head
Trivernis 5 years ago
parent 1343dbf249
commit d69740851e

@ -1,6 +1,7 @@
package net.trivernis.chunkmaster
import net.trivernis.chunkmaster.commands.CommandGenerate
import net.trivernis.chunkmaster.commands.CommandListGenTasks
import net.trivernis.chunkmaster.lib.GenerationManager
import net.trivernis.chunkmaster.lib.Spiral
import org.bukkit.plugin.java.JavaPlugin
@ -20,6 +21,7 @@ class Chunkmaster: JavaPlugin() {
generationManager = GenerationManager(this, server)
generationManager.init()
getCommand("generate")?.setExecutor(CommandGenerate(this))
getCommand("listgentasks")?.setExecutor(CommandListGenTasks(this))
server.pluginManager.registerEvents(ChunkmasterEvents(this, server), this)
}

@ -11,7 +11,8 @@ class ChunkmasterEvents(private val chunkmaster: Chunkmaster, private val server
* Autostart generation tasks
*/
fun onPlayerQuit(event: PlayerQuitEvent) {
if (server.onlinePlayers.size == 1 && server.onlinePlayers.contains(event.player)) {
if (server.onlinePlayers.size == 1 && server.onlinePlayers.contains(event.player) ||
server.onlinePlayers.isEmpty()) {
chunkmaster.generationManager.startAll()
chunkmaster.logger.info("Server is empty. Starting chunk generation tasks.")
}

@ -0,0 +1,24 @@
package net.trivernis.chunkmaster.commands
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.chat.ComponentBuilder
import net.trivernis.chunkmaster.Chunkmaster
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
class CommandListGenTasks(private val chunkmaster: Chunkmaster): CommandExecutor {
/**
* Responds with a list of running generation tasks.
*/
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
val runningTasks = chunkmaster.generationManager.tasks
val response = ComponentBuilder("Currently running generation tasks").color(ChatColor.BLUE)
for (task in runningTasks) {
response.append("\n - #${task.id}: ${task.generationTask.world}, Progress ${task.generationTask.count}")
}
response.color(ChatColor.GREEN)
sender.spigot().sendMessage(*response.create())
return true
}
}

@ -11,7 +11,8 @@ import java.lang.NullPointerException
class GenerationManager(private val chunkmaster: Chunkmaster, private val server: Server) {
private val tasks: HashSet<TaskEntry> = HashSet()
val tasks: HashSet<TaskEntry> = HashSet()
get() = field
/**
* Adds a generation task
@ -60,7 +61,9 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
fun init() {
chunkmaster.logger.info("Creating task to load chunk generation Tasks later...")
server.scheduler.runTaskLater(chunkmaster, Runnable {
startAll() // run startAll after 10 seconds
if (server.onlinePlayers.isEmpty()) {
startAll() // run startAll after 10 seconds if empty
}
}, 200)
}
@ -108,7 +111,7 @@ class GenerationManager(private val chunkmaster: Chunkmaster, private val server
for (task in tasks) {
try {
val genTask = task.generationTask
server.consoleSender.sendMessage("Task #${task.id} running for \"${genTask.world.name}\"." +
server.consoleSender.sendMessage("Task #${task.id} running for \"${genTask.world.name}\". " +
"Progress ${task.generationTask.count} chunks. Last Chunk: ${genTask.lastChunk.x}, ${genTask.lastChunk.z}")
val updateStatement = chunkmaster.sqliteConnection.prepareStatement("""
UPDATE generation_tasks SET last_x = ?, last_z = ?

@ -10,12 +10,20 @@ commands:
description: Generates chunks starting from the world spawnpoint
permission: chumkmaster.generate
usage: /generate [world]
listgentasks:
description: Lists all generation tasks
permission: chunkmaster.listgentasks
usage: /listgentasks
permissions:
cunkmaster.generate:
description: Allows generate command
default: op
chunkmaster.listgentasks:
description: Lists all generation tasks
default: op
chunkmaster.*:
description: Wildcard permission
default: op
children:
- chunkmaster.generate
- chunkmaster.generate
- chunkmaster.listgentasks
Loading…
Cancel
Save