Add stats command to print chunkmaster stats

- Server information
- Worlds chunk information
feature/stats-command
trivernis 4 years ago
parent 8ad6bc44af
commit 615280a2ed

@ -40,6 +40,7 @@ All features can be accessed with the command `/chunkmaster` or the aliases `/ch
- `/chunkmaster tpchunk <X> <Z>` Teleports you to the specified chunk coordinates. - `/chunkmaster tpchunk <X> <Z>` Teleports you to the specified chunk coordinates.
- `/<command> setCenter [[<world>] <chunkX> <chunkZ>]]` - sets the center chunk of the world - `/<command> setCenter [[<world>] <chunkX> <chunkZ>]]` - sets the center chunk of the world
- `/<command> getCenter [<world>]` - returns the center chunk of the world - `/<command> getCenter [<world>]` - returns the center chunk of the world
- `/<command> stats [<world>]` - returns the stats of the server or a specific world
#### Examples #### Examples
**Generate a 100 chunks * 100 blocks square around the center:** **Generate a 100 chunks * 100 blocks square around the center:**

@ -22,7 +22,7 @@ idea {
} }
group "net.trivernis" group "net.trivernis"
version "1.0.1" version "1.2.0"
sourceCompatibility = 1.8 sourceCompatibility = 1.8

@ -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<String>
): MutableList<String> {
return sender.server.worlds.map { it.name }.toMutableList()
}
override fun execute(sender: CommandSender, args: List<String>): 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
}
}

@ -86,5 +86,8 @@ class CommandChunkmaster(private val chunkmaster: Chunkmaster, private val serve
val cmdGetCenter = CmdGetCenter(chunkmaster) val cmdGetCenter = CmdGetCenter(chunkmaster)
commands[cmdGetCenter.name] = cmdGetCenter commands[cmdGetCenter.name] = cmdGetCenter
val cmdStats = CmdStats(chunkmaster)
commands[cmdStats.name] = cmdStats
} }
} }

@ -22,6 +22,11 @@ abstract class GenerationTask(
abstract var count: Int abstract var count: Int
abstract var endReached: Boolean abstract var endReached: Boolean
val loadedChunksCount: Int
get() {
return loadedChunks.size
}
protected val loadedChunks: HashSet<Chunk> = HashSet() protected val loadedChunks: HashSet<Chunk> = HashSet()
var lastChunkCoords = ChunkCoordinates(startChunk.x, startChunk.z) var lastChunkCoords = ChunkCoordinates(startChunk.x, startChunk.z)
protected set protected set

@ -61,3 +61,15 @@ PLUGIN_DETECTED = Detected %s version %s
RESUME_PLAYER_LEAVE = The player count is smaller than the configured pause value. Resuming generation... 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_PLAYER_JOIN = The player count has reached the pause value. Pausing generation...
PAUSE_MANUALLY = Generation was manually paused. Not resuming automatically. 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

@ -61,3 +61,15 @@ 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... 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_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. 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

@ -61,3 +61,15 @@ PLUGIN_DETECTED = Detected %s version %s
RESUME_PLAYER_LEAVE = The player count is smaller than the configured pause value. Resuming generation... 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_PLAYER_JOIN = The player count has reached the pause value. Pausing generation...
PAUSE_MANUALLY = Generation was manually paused. Not resuming automatically. 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

@ -1,6 +1,6 @@
main: net.trivernis.chunkmaster.Chunkmaster main: net.trivernis.chunkmaster.Chunkmaster
name: Chunkmaster name: Chunkmaster
version: '1.0.1' version: '1.2.0'
description: Chunk commands plugin. description: Chunk commands plugin.
author: Trivernis author: Trivernis
website: trivernis.net website: trivernis.net
@ -22,6 +22,7 @@ commands:
/<command> tpchunk <chunkX> <chunkZ> - teleports you to the chunk with the given chunk coordinates /<command> tpchunk <chunkX> <chunkZ> - teleports you to the chunk with the given chunk coordinates
/<command> setCenter [[<world>] <chunkX> <chunkZ>]] - sets the center chunk of the world /<command> setCenter [[<world>] <chunkX> <chunkZ>]] - sets the center chunk of the world
/<command> getCenter [<world>] - returns the center chunk of the world /<command> getCenter [<world>] - returns the center chunk of the world
/<command> stats [<world>] - returns some chunk stats for the world or the whole server
aliases: aliases:
- chm - chm
- chunkm - chunkm

Loading…
Cancel
Save