mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-12 13:24:36 +01:00
Add /status command
This commit is contained in:
@@ -226,7 +226,7 @@ public class LunarCore {
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String getGitHash() {
|
||||
public static String getGitHash() {
|
||||
// Use a string builder in case one of the build config fields are missing
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
@@ -246,7 +246,7 @@ public class LunarCore {
|
||||
}
|
||||
|
||||
if (builder.isEmpty()) {
|
||||
return "";
|
||||
return "UNKNOWN";
|
||||
} else {
|
||||
return builder.toString();
|
||||
}
|
||||
@@ -274,6 +274,14 @@ public class LunarCore {
|
||||
timeOffset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the memory usage of the server, in megabytes.
|
||||
*/
|
||||
public static long getMemoryUsage() {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
return (runtime.totalMemory() - runtime.freeMemory()) / 1_048_576L;
|
||||
}
|
||||
|
||||
// Server console
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package emu.lunarcore.command.commands;
|
||||
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.command.Command;
|
||||
import emu.lunarcore.command.CommandArgs;
|
||||
import emu.lunarcore.command.CommandHandler;
|
||||
|
||||
@Command(label = "status", aliases = {"st", "stats"}, permission = "admin.status", desc = "/status. Displays the status of the server.")
|
||||
public class StatusCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(CommandArgs args) {
|
||||
// Run garbage collector
|
||||
if (!args.hasFlag("-nogc")) {
|
||||
System.gc();
|
||||
}
|
||||
|
||||
// Show status
|
||||
args.sendMessage("Showing server status");
|
||||
|
||||
args.sendMessage("Git hash: " + LunarCore.getGitHash());
|
||||
args.sendMessage("Memory usage: " + LunarCore.getMemoryUsage() + " MB");
|
||||
|
||||
if (LunarCore.getGameServer() != null) {
|
||||
args.sendMessage("Player count: " + LunarCore.getGameServer().getPlayerCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,12 @@ public class GameServer extends KcpServer {
|
||||
public GameServerConfig getServerConfig() {
|
||||
return this.serverConfig;
|
||||
}
|
||||
|
||||
public int getPlayerCount() {
|
||||
synchronized (this.players) {
|
||||
return this.players.size();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPlayer(Player player) {
|
||||
synchronized (this.players) {
|
||||
|
||||
Reference in New Issue
Block a user