Tidy up /gc's TPS output.

This commit is contained in:
KHobbits 2013-05-18 21:42:02 +01:00
parent 727c53eb2b
commit 293406a603
3 changed files with 20 additions and 12 deletions

View File

@ -18,12 +18,13 @@ public class EssentialsTimer implements Runnable
private int skip2 = 0;
private final long maxTime = 10 * 1000000;
private final long tickInterval = 50;
EssentialsTimer(final IEssentials ess)
{
this.ess = ess;
history.add(20d);
}
@Override
public void run()
{
@ -39,7 +40,7 @@ public class EssentialsTimer implements Runnable
history.remove();
}
double tps = tickInterval * 1000000.0 / timeSpent;
if (tps <= 20)
if (tps <= 21)
{
history.add(tps);
}
@ -73,7 +74,7 @@ public class EssentialsTimer implements Runnable
ess.getLogger().log(Level.WARNING, "EssentialsTimer Error:", e);
}
}
count = 0;
final Iterator<String> iterator = onlineUsers.iterator();
while (iterator.hasNext())
@ -104,7 +105,7 @@ public class EssentialsTimer implements Runnable
user.resetInvulnerabilityAfterTeleport();
}
}
public double getAverageTPS()
{
double avg = 0;
@ -114,7 +115,7 @@ public class EssentialsTimer implements Runnable
{
avg += f;
}
}
}
return avg / history.size();
}
}

View File

@ -357,13 +357,13 @@ public class Util
break;
}
}
if (isBlockUnsafe(world, x, y, z))
{
x = Math.round(loc.getX()) == origX ? x - 1 : x + 1;
z = Math.round(loc.getZ()) == origZ ? z - 1 : z + 1;
}
int i = 0;
while (isBlockUnsafe(world, x, y, z))
{
@ -527,12 +527,12 @@ public class Util
}
return is;
}
private static DecimalFormat dFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
private static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
public static String formatAsCurrency(final BigDecimal value)
{
dFormat.setRoundingMode(RoundingMode.FLOOR);
String str = dFormat.format(value);
currencyFormat.setRoundingMode(RoundingMode.FLOOR);
String str = currencyFormat.format(value);
if (str.endsWith(".00"))
{
str = str.substring(0, str.length() - 3);
@ -549,6 +549,13 @@ public class Util
{
return ess.getSettings().getCurrencySymbol() + formatAsCurrency(value);
}
private static DecimalFormat threeDPlaces = new DecimalFormat("#,###.###");
public static String formatDouble(final double value)
{
threeDPlaces.setRoundingMode(RoundingMode.HALF_UP);
return threeDPlaces.format(value);
}
public static boolean isInt(final String sInt)
{

View File

@ -36,7 +36,7 @@ public class Commandgc extends EssentialsCommand
}
sender.sendMessage(_("uptime", Util.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime())));
sender.sendMessage(_("tps", "" + color + tps));
sender.sendMessage(_("tps", "" + color + Util.formatDouble(tps)));
sender.sendMessage(_("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024)));
sender.sendMessage(_("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024)));
sender.sendMessage(_("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024)));