diff --git a/README.md b/README.md index 177112e..763c0fd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ All features can be accessed with the command `/chunkmaster` or the aliases `/ch - `/chunkmaster tpchunk ` Teleports you to the specified chunk coordinates. - `/ setCenter [[] ]]` - sets the center chunk of the world - `/ getCenter []` - returns the center chunk of the world +- `/ stats []` - returns the stats of the server or a specific world #### Examples **Generate a 100 chunks * 100 blocks square around the center:** diff --git a/build.gradle b/build.gradle index be69490..12f3885 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ idea { } group "net.trivernis" -version "1.0.1" +version "1.2.0" sourceCompatibility = 1.8 diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdCancel.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdCancel.kt index 0bc262f..65e6e47 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdCancel.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdCancel.kt @@ -31,10 +31,11 @@ class CmdCancel(private val chunkmaster: Chunkmaster): Subcommand { */ override fun execute(sender: CommandSender, args: List): Boolean { return if (args.isNotEmpty()) { - val index = if (args[0].toIntOrNull() != null) { + val entry = chunkmaster.generationManager.tasks.find { it.generationTask.world.name == args[0] } + val index = if (args[0].toIntOrNull() != null && entry == null) { args[0].toInt() } else { - chunkmaster.generationManager.tasks.find { it.generationTask.world.name == args[0] }?.id + entry?.id } if (index != null && chunkmaster.generationManager.removeTask(index)) { diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdGenerate.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdGenerate.kt index baef0b9..a9eccae 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdGenerate.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdGenerate.kt @@ -55,7 +55,7 @@ class CmdGenerate(private val chunkmaster: Chunkmaster): Subcommand { return false } } - if (args[0].toIntOrNull() != null) { + if (args[0].toIntOrNull() != null && sender.server.worlds.find { it.name == args[0] } == null) { if (sender !is Player) { sender.sendMessage(chunkmaster.langManager.getLocalized("WORLD_NAME_REQUIRED")) return false diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdStats.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdStats.kt new file mode 100644 index 0000000..4390bf9 --- /dev/null +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CmdStats.kt @@ -0,0 +1,68 @@ +package net.trivernis.chunkmaster.commands + +import net.trivernis.chunkmaster.Chunkmaster +import net.trivernis.chunkmaster.lib.Subcommand +import org.bukkit.World +import org.bukkit.command.Command +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +class CmdStats(private val chunkmaster: Chunkmaster): Subcommand { + override val name = "stats" + + override fun onTabComplete( + sender: CommandSender, + command: Command, + alias: String, + args: List + ): MutableList { + return sender.server.worlds.map { it.name }.toMutableList() + } + + override fun execute(sender: CommandSender, args: List): Boolean { + if (args.isNotEmpty()) { + val world = sender.server.getWorld(args[0]) + if (world == null) { + sender.sendMessage(chunkmaster.langManager.getLocalized("STATS_HEADER") + "\n" + + chunkmaster.langManager.getLocalized("WORLD_NOT_FOUND", args[0])) + return false + } + sender.sendMessage(getWorldStatsMessage(sender, world)) + } else { + sender.sendMessage(getServerStatsMessage(sender)) + } + + return true + } + + private fun getWorldStatsMessage(sender: CommandSender, world: World): String { + var message = """ + ${chunkmaster.langManager.getLocalized("STATS_WORLD_NAME", world.name)} + ${chunkmaster.langManager.getLocalized("STATS_ENTITY_COUNT", world.entities.size)} + ${chunkmaster.langManager.getLocalized("STATS_LOADED_CHUNKS", world.loadedChunks.size)} + """.trimIndent() + val task = chunkmaster.generationManager.tasks.find { it.generationTask.world == world } + if (task != null) { + message += "\n" + chunkmaster.langManager.getLocalized("STATS_PLUGIN_LOADED_CHUNKS", task.generationTask.loadedChunksCount) + } + return message + } + + private fun getServerStatsMessage(sender: CommandSender): String { + val runtime = Runtime.getRuntime() + val memUsed = runtime.maxMemory() - runtime.freeMemory() + var message = "\n" + """ + ${chunkmaster.langManager.getLocalized("STATS_HEADER")} + + ${chunkmaster.langManager.getLocalized("STATS_SERVER")} + ${chunkmaster.langManager.getLocalized("STATS_SERVER_VERSION", sender.server.version)} + ${chunkmaster.langManager.getLocalized("STATS_PLUGIN_VERSION", chunkmaster.description.version)} + ${chunkmaster.langManager.getLocalized("STATS_MEMORY", memUsed/1000000, runtime.maxMemory()/1000000, (memUsed.toFloat()/runtime.maxMemory().toFloat()) * 100)} + ${chunkmaster.langManager.getLocalized("STATS_CORES", runtime.availableProcessors())} + """.trimIndent() + for (world in sender.server.worlds) { + message += "\n\n" + getWorldStatsMessage(sender, world) + } + return message + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/trivernis/chunkmaster/commands/CommandChunkmaster.kt b/src/main/kotlin/net/trivernis/chunkmaster/commands/CommandChunkmaster.kt index 30a0bdb..e33211d 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/commands/CommandChunkmaster.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/commands/CommandChunkmaster.kt @@ -86,5 +86,8 @@ class CommandChunkmaster(private val chunkmaster: Chunkmaster, private val serve val cmdGetCenter = CmdGetCenter(chunkmaster) commands[cmdGetCenter.name] = cmdGetCenter + + val cmdStats = CmdStats(chunkmaster) + commands[cmdStats.name] = cmdStats } } \ No newline at end of file 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 28df798..e3e889d 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/generation/GenerationTask.kt @@ -22,6 +22,11 @@ abstract class GenerationTask( abstract var count: Int abstract var endReached: Boolean + val loadedChunksCount: Int + get() { + return loadedChunks.size + } + protected val loadedChunks: HashSet = HashSet() var lastChunkCoords = ChunkCoordinates(startChunk.x, startChunk.z) protected set diff --git a/src/main/resources/i18n/DEFAULT.i18n.properties b/src/main/resources/i18n/DEFAULT.i18n.properties index 6e9ec32..283d4c3 100644 --- a/src/main/resources/i18n/DEFAULT.i18n.properties +++ b/src/main/resources/i18n/DEFAULT.i18n.properties @@ -60,4 +60,16 @@ PLUGIN_DETECTED = Detected %s version %s RESUME_PLAYER_LEAVE = The player count is smaller than the configured pause value. Resuming generation... PAUSE_PLAYER_JOIN = The player count has reached the pause value. Pausing generation... -PAUSE_MANUALLY = Generation was manually paused. Not resuming automatically. \ No newline at end of file +PAUSE_MANUALLY = Generation was manually paused. Not resuming automatically. + +STATS_HEADER = §nStats§r +STATS_SERVER = §lServer Stats§r +STATS_SERVER_VERSION = - Server Version: §2%s§r +STATS_PLUGIN_VERSION = - Plugin Version: §2%s§r +STATS_MEMORY = - Memory (u/a): §2%d mb / %d mb = (%.2f percent)§r +STATS_CORES = - Cores: §2%d§r + +STATS_WORLD_NAME = §l%s§r +STATS_ENTITY_COUNT = - §2%d§r Entities +STATS_LOADED_CHUNKS = - §2%d§r Loaded Chunks +STATS_PLUGIN_LOADED_CHUNKS = - §2%d§r Chunks Loaded by Chunkmaster \ No newline at end of file diff --git a/src/main/resources/i18n/de.i18n.properties b/src/main/resources/i18n/de.i18n.properties index 33f7a10..ece9aa2 100644 --- a/src/main/resources/i18n/de.i18n.properties +++ b/src/main/resources/i18n/de.i18n.properties @@ -60,4 +60,16 @@ PLUGIN_DETECTED = Plugin %s in der Version %s gefunden! RESUME_PLAYER_LEAVE = Die Anzahl der Spieler hat den festgelegen Wert zum Pausieren unterschritten. Setze Generieren fort... PAUSE_PLAYER_JOIN = Die Anzahl der Spieler hat den festgelegten Wert zum Pausieren erreicht. Pausiere... -PAUSE_MANUALLY = Das Generieren wurde manuell pausiert und wird deswegen nicht automatisch fortgesetzt. \ No newline at end of file +PAUSE_MANUALLY = Das Generieren wurde manuell pausiert und wird deswegen nicht automatisch fortgesetzt. + +STATS_HEADER = §nStatistiken§r +STATS_SERVER = §lServer Statistik§r +STATS_SERVER_VERSION = - Server Version: §2%s§r +STATS_PLUGIN_VERSION = - Plugin Version: §2%s§r +STATS_MEMORY = - Arbeitsspeicher (u/a): §2%d mb / %d mb = (%.2f percent)§r +STATS_CORES = - Kerne: §2%d§r + +STATS_WORLD_NAME = §l%s§r +STATS_ENTITY_COUNT = - §2%d§r Entities +STATS_LOADED_CHUNKS = - §2%d§r Geladene Chunks +STATS_PLUGIN_LOADED_CHUNKS = - §2%d§r von Chunkmaster geladene Chunks \ No newline at end of file diff --git a/src/main/resources/i18n/en.i18n.properties b/src/main/resources/i18n/en.i18n.properties index 6e9ec32..283d4c3 100644 --- a/src/main/resources/i18n/en.i18n.properties +++ b/src/main/resources/i18n/en.i18n.properties @@ -60,4 +60,16 @@ PLUGIN_DETECTED = Detected %s version %s RESUME_PLAYER_LEAVE = The player count is smaller than the configured pause value. Resuming generation... PAUSE_PLAYER_JOIN = The player count has reached the pause value. Pausing generation... -PAUSE_MANUALLY = Generation was manually paused. Not resuming automatically. \ No newline at end of file +PAUSE_MANUALLY = Generation was manually paused. Not resuming automatically. + +STATS_HEADER = §nStats§r +STATS_SERVER = §lServer Stats§r +STATS_SERVER_VERSION = - Server Version: §2%s§r +STATS_PLUGIN_VERSION = - Plugin Version: §2%s§r +STATS_MEMORY = - Memory (u/a): §2%d mb / %d mb = (%.2f percent)§r +STATS_CORES = - Cores: §2%d§r + +STATS_WORLD_NAME = §l%s§r +STATS_ENTITY_COUNT = - §2%d§r Entities +STATS_LOADED_CHUNKS = - §2%d§r Loaded Chunks +STATS_PLUGIN_LOADED_CHUNKS = - §2%d§r Chunks Loaded by Chunkmaster \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 33abf55..9fb30bf 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: '1.0.1' +version: '1.2.0' description: Chunk commands plugin. author: Trivernis website: trivernis.net @@ -22,6 +22,7 @@ commands: / tpchunk - teleports you to the chunk with the given chunk coordinates / setCenter [[] ]] - sets the center chunk of the world / getCenter [] - returns the center chunk of the world + / stats [] - returns some chunk stats for the world or the whole server aliases: - chm - chunkm