2011-03-19 23:39:51 +01:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 21:59:39 +02:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2013-06-08 23:31:19 +02:00
|
|
|
import com.earth2me.essentials.utils.DateUtil;
|
2013-06-09 22:35:51 +02:00
|
|
|
import com.earth2me.essentials.utils.NumberUtil;
|
2020-10-03 19:46:05 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Chunk;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.World;
|
2015-04-15 06:06:16 +02:00
|
|
|
|
2012-09-15 23:04:18 +02:00
|
|
|
import java.lang.management.ManagementFactory;
|
2013-01-20 21:35:41 +01:00
|
|
|
import java.util.List;
|
2014-05-04 20:39:10 +02:00
|
|
|
import java.util.logging.Level;
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
public class Commandgc extends EssentialsCommand {
|
|
|
|
public Commandgc() {
|
|
|
|
super("gc");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
2020-10-03 19:46:05 +02:00
|
|
|
final double tps = ess.getTimer().getAverageTPS();
|
|
|
|
final ChatColor color;
|
2015-04-15 06:06:16 +02:00
|
|
|
if (tps >= 18.0) {
|
|
|
|
color = ChatColor.GREEN;
|
|
|
|
} else if (tps >= 15.0) {
|
|
|
|
color = ChatColor.YELLOW;
|
|
|
|
} else {
|
|
|
|
color = ChatColor.RED;
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("uptime", DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime()));
|
|
|
|
sender.sendTl("tps", "" + color + NumberUtil.formatDouble(tps));
|
|
|
|
sender.sendTl("gcmax", Runtime.getRuntime().maxMemory() / 1024 / 1024);
|
|
|
|
sender.sendTl("gctotal", Runtime.getRuntime().totalMemory() / 1024 / 1024);
|
|
|
|
sender.sendTl("gcfree", Runtime.getRuntime().freeMemory() / 1024 / 1024);
|
2015-04-15 06:06:16 +02:00
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
final List<World> worlds = server.getWorlds();
|
|
|
|
for (final World w : worlds) {
|
2015-04-15 06:06:16 +02:00
|
|
|
String worldType = "World";
|
|
|
|
switch (w.getEnvironment()) {
|
|
|
|
case NETHER:
|
|
|
|
worldType = "Nether";
|
|
|
|
break;
|
|
|
|
case THE_END:
|
|
|
|
worldType = "The End";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tileEntities = 0;
|
|
|
|
|
|
|
|
try {
|
2020-10-03 19:46:05 +02:00
|
|
|
for (final Chunk chunk : w.getLoadedChunks()) {
|
2015-04-15 06:06:16 +02:00
|
|
|
tileEntities += chunk.getTileEntities().length;
|
|
|
|
}
|
2020-10-03 19:46:05 +02:00
|
|
|
} catch (final java.lang.ClassCastException ex) {
|
2022-06-27 20:54:10 +02:00
|
|
|
ess.getLogger().log(Level.SEVERE, "Corrupted chunk data on world " + w, ex);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2024-02-03 21:38:14 +01:00
|
|
|
sender.sendTl("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size(), tileEntities);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|