2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.commands;
|
2012-12-27 23:27:59 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
2013-08-09 13:40:08 +00:00
|
|
|
import java.text.DecimalFormat;
|
2013-08-10 16:39:50 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
2013-08-10 16:39:50 +00:00
|
|
|
import org.apache.commons.lang.math.DoubleRange;
|
2013-08-09 13:40:08 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2012-12-27 23:27:59 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2013-08-09 13:40:08 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2013-08-10 16:39:50 +00:00
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
2012-12-27 23:27:59 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(description = "View ticks-per-second", usage = "/<command>")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_health extends FreedomCommand
|
2012-12-27 23:27:59 +00:00
|
|
|
{
|
2013-08-10 16:39:50 +00:00
|
|
|
private static final int BYTES_PER_MB = 1024 * 1024;
|
|
|
|
private static final DoubleRange TPS_RANGE = new DoubleRange(20.0 - 0.1, 20.0 + 0.1);
|
|
|
|
|
2012-12-27 23:27:59 +00:00
|
|
|
@Override
|
|
|
|
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2013-08-10 16:39:50 +00:00
|
|
|
Runtime runtime = Runtime.getRuntime();
|
|
|
|
long usedMem = runtime.totalMemory() - runtime.freeMemory();
|
|
|
|
|
|
|
|
playerMsg("Reserved Memory: " + (double) runtime.totalMemory() / (double) BYTES_PER_MB + "mb");
|
|
|
|
playerMsg("Used Memory: " + new DecimalFormat("#").format((double) usedMem / (double) BYTES_PER_MB) + "mb (" + new DecimalFormat("#").format(((double) usedMem / (double) runtime.totalMemory()) * 100.0) + "%)");
|
|
|
|
playerMsg("Max Memory: " + (double) runtime.maxMemory() / (double) BYTES_PER_MB + "mb");
|
|
|
|
playerMsg("Calculating ticks per second, please wait...");
|
2013-08-10 00:11:17 +00:00
|
|
|
|
2013-08-09 13:40:08 +00:00
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-08-10 16:39:50 +00:00
|
|
|
TFM_TickMeter tickMeter = new TFM_TickMeter(plugin);
|
|
|
|
tickMeter.startTicking();
|
|
|
|
Thread.sleep(2500);
|
|
|
|
final double ticksPerSecond = tickMeter.stopTicking();
|
2013-08-10 00:11:17 +00:00
|
|
|
|
2013-08-09 13:40:08 +00:00
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
2013-08-10 00:11:17 +00:00
|
|
|
public void run()
|
|
|
|
{
|
2013-08-10 16:39:50 +00:00
|
|
|
playerMsg("Ticks per second: " + (TPS_RANGE.containsDouble(ticksPerSecond) ? ChatColor.GREEN : ChatColor.RED) + ticksPerSecond);
|
2013-08-09 13:40:08 +00:00
|
|
|
}
|
2013-08-10 16:39:50 +00:00
|
|
|
}.runTask(plugin);
|
2013-08-09 13:40:08 +00:00
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2013-08-09 13:40:08 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-08-09 13:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-10 16:39:50 +00:00
|
|
|
}.runTaskAsynchronously(plugin);
|
2013-08-09 13:40:08 +00:00
|
|
|
|
2012-12-27 23:27:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-10 16:39:50 +00:00
|
|
|
|
|
|
|
private class TFM_TickMeter
|
|
|
|
{
|
|
|
|
private final AtomicInteger ticks = new AtomicInteger();
|
|
|
|
private final TotalFreedomMod plugin;
|
|
|
|
private long startTime;
|
|
|
|
private BukkitTask task;
|
|
|
|
|
|
|
|
public TFM_TickMeter(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startTicking()
|
|
|
|
{
|
|
|
|
startTime = System.currentTimeMillis();
|
|
|
|
ticks.set(0);
|
|
|
|
|
|
|
|
task = new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
ticks.incrementAndGet();
|
|
|
|
}
|
|
|
|
}.runTaskTimer(plugin, 0L, 1L);
|
|
|
|
}
|
|
|
|
|
|
|
|
public double stopTicking()
|
|
|
|
{
|
|
|
|
task.cancel();
|
|
|
|
long elapsed = System.currentTimeMillis() - startTime;
|
|
|
|
int tickCount = ticks.get();
|
|
|
|
|
|
|
|
return (double) tickCount / ((double) elapsed / 1000.0);
|
|
|
|
}
|
|
|
|
}
|
2012-12-27 23:27:59 +00:00
|
|
|
}
|