64 lines
2.1 KiB
Java
64 lines
2.1 KiB
Java
/**
|
|
*
|
|
*/
|
|
package cn.citycraft.SimpleEssential.command;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Chunk;
|
|
import org.bukkit.World;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandException;
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
|
import cn.citycraft.PluginHelper.utils.StringUtil;
|
|
import cn.citycraft.PluginHelper.utils.SystemUtil;
|
|
import cn.citycraft.SimpleEssential.SimpleEssential;
|
|
import cn.citycraft.SimpleEssential.config.I18n;
|
|
|
|
/**
|
|
* 传送到顶部命令
|
|
*
|
|
* @author 蒋天蓓
|
|
* 2015年8月12日下午2:04:05
|
|
*
|
|
*/
|
|
public class CommandGc extends BaseCommand {
|
|
SimpleEssential plugin;
|
|
|
|
/**
|
|
* @param name
|
|
*/
|
|
public CommandGc(final SimpleEssential main) {
|
|
super("gc", "mem", "segc", "semem");
|
|
this.plugin = main;
|
|
setDescription("清理内存");
|
|
}
|
|
|
|
@Override
|
|
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
|
final Runtime rt = Runtime.getRuntime();
|
|
if (label.equalsIgnoreCase("gc") || label.equalsIgnoreCase("segc")) {
|
|
rt.gc();
|
|
}
|
|
sender.sendMessage(I18n.p("Gc.runTime", StringUtil.formatDate(SystemUtil.getRunTime())));
|
|
sender.sendMessage(I18n.p("Gc.Processors", rt.availableProcessors()));
|
|
sender.sendMessage(I18n.p("Gc.maxMem", StringUtil.b2mb(rt.maxMemory())));
|
|
sender.sendMessage(I18n.p("Gc.totalMem", StringUtil.b2mb(rt.totalMemory())));
|
|
sender.sendMessage(I18n.p("Gc.freeMem", StringUtil.b2mb(rt.freeMemory())));
|
|
for (final World wd : Bukkit.getWorlds()) {
|
|
int tileEntities = 0;
|
|
try {
|
|
for (final Chunk chunk : wd.getLoadedChunks()) {
|
|
tileEntities += chunk.getTileEntities().length;
|
|
}
|
|
} catch (final ClassCastException ex) {
|
|
org.bukkit.Bukkit.getLogger().log(Level.SEVERE, "无法读取区块信息 错误世界: " + wd, ex);
|
|
}
|
|
sender.sendMessage(I18n.p("World.info", wd.getName(), wd.getEnvironment().toString(), wd.getLoadedChunks().length, wd.getEntities().size(), tileEntities, wd.getPlayers().size()));
|
|
}
|
|
}
|
|
}
|