Formatting cleanup.

Added ignore for unchecked cast warning.
This commit is contained in:
Steven Lawson 2013-08-09 20:11:17 -04:00
parent bcd9658b3d
commit d4dfe06ec0
5 changed files with 15 additions and 95 deletions

View File

@ -18,10 +18,9 @@ public class Command_health extends TFM_Command
@Override @Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
new BukkitRunnable() new BukkitRunnable()
{ {
@Override @Override
public void run() public void run()
{ {
@ -36,11 +35,12 @@ public class Command_health extends TFM_Command
final int mb = 1048576; // 1024 * 1024 final int mb = 1048576; // 1024 * 1024
final float usedMem = runtime.totalMemory() - runtime.freeMemory(); final float usedMem = runtime.totalMemory() - runtime.freeMemory();
new BukkitRunnable() new BukkitRunnable()
{ {
@Override @Override
public void run() { public void run()
{
playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb"); playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb");
playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format((usedMem / runtime.totalMemory()) * 100) + "%)"); playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format((usedMem / runtime.totalMemory()) * 100) + "%)");
playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb"); playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb");
@ -54,7 +54,6 @@ public class Command_health extends TFM_Command
TFM_Log.warning(ExceptionUtils.getStackTrace(iex)); TFM_Log.warning(ExceptionUtils.getStackTrace(iex));
} }
} }
}.runTaskAsynchronously(TotalFreedomMod.plugin); }.runTaskAsynchronously(TotalFreedomMod.plugin);
return true; return true;

View File

@ -9,10 +9,11 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH) @CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
@CommandParameters(description = "Shows the status of all Mojang services", usage = "/<command>") @CommandParameters(description = "Shows the status of all Mojang services", usage = "/<command>")
public class Command_services extends TFM_Command { public class Command_services extends TFM_Command
{
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
playerMsg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE); playerMsg("Mojang Services" + ChatColor.WHITE + ":", ChatColor.BLUE);
for (TFM_ServiceChecker_ServiceStatus service : TFM_ServiceChecker.getInstance().getAllStatuses()) for (TFM_ServiceChecker_ServiceStatus service : TFM_ServiceChecker.getInstance().getAllStatuses())
@ -24,5 +25,4 @@ public class Command_services extends TFM_Command {
return true; return true;
} }
} }

View File

@ -1,25 +1,12 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH) @CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
@CommandParameters(description = "Show misc. server info.", usage = "/<command>") @CommandParameters(description = "Show misc. server info.", usage = "/<command>")
@ -49,68 +36,6 @@ public class Command_status extends TFM_Command
{ {
playerMsg(String.format("World %d: %s - %d players.", i++, world.getName(), world.getPlayers().size()), ChatColor.BLUE); playerMsg(String.format("World %d: %s - %d players.", i++, world.getName(), world.getPlayers().size()), ChatColor.BLUE);
} }
/* Moved to TFM_ServiceChecker and Command_services
new BukkitRunnable()
{
@SuppressWarnings("unchecked")
@Override
public void run()
{
try
{
URL mojang_status = new URL("http://status.mojang.com/check");
BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream()));
JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine());
in.close();
Map<String, Boolean> service_status = new HashMap<String, Boolean>();
Iterator status_it = status_json.iterator();
while (status_it.hasNext())
{
JSONObject service = (JSONObject) status_it.next();
Iterator service_it = service.entrySet().iterator();
while (service_it.hasNext())
{
Entry<String, String> pair = (Entry<String, String>) service_it.next();
service_status.put(pair.getKey(), (pair.getValue().equals("green") ? Boolean.TRUE : Boolean.FALSE));
}
}
final List<String> status_output = new ArrayList<String>();
Iterator<Entry<String, Boolean>> output_it = service_status.entrySet().iterator();
while (output_it.hasNext())
{
Entry<String, Boolean> pair = output_it.next();
String service_name = pair.getKey();
boolean service_online = pair.getValue().booleanValue();
if (SERVICE_MAP.containsKey(service_name))
{
service_name = SERVICE_MAP.get(service_name);
}
status_output.add(String.format("%s is %s", service_name, (service_online ? ChatColor.GREEN + "ONLINE" + ChatColor.GRAY : ChatColor.RED + "OFFLINE" + ChatColor.GRAY)));
}
new BukkitRunnable()
{
@Override
public void run()
{
playerMsg(String.format("Mojang Service Status: %s.", StringUtils.join(status_output, ", ")), ChatColor.GRAY);
}
}.runTask(plugin);
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
}.runTaskAsynchronously(plugin);
*/
return true; return true;
} }

View File

@ -12,7 +12,7 @@ public class Command_tfm extends TFM_Command
{ {
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
playerMsg("TotalFreedomMod for 'TotalFreedom', the original all-op server.", ChatColor.GOLD); playerMsg("TotalFreedomMod for 'TotalFreedom', the original all-op server.", ChatColor.GOLD);
playerMsg(String.format("Version " + ChatColor.BLUE + "%s.%s" + ChatColor.BLUE + ", built %s.", TotalFreedomMod.pluginVersion, TotalFreedomMod.buildNumber, TotalFreedomMod.buildDate), ChatColor.GOLD); playerMsg(String.format("Version " + ChatColor.BLUE + "%s.%s" + ChatColor.BLUE + ", built %s.", TotalFreedomMod.pluginVersion, TotalFreedomMod.buildNumber, TotalFreedomMod.buildDate), ChatColor.GOLD);
playerMsg("Created by Madgeek1450 and DarthSalamon.", ChatColor.GOLD); playerMsg("Created by Madgeek1450 and DarthSalamon.", ChatColor.GOLD);
@ -20,5 +20,4 @@ public class Command_tfm extends TFM_Command
return true; return true;
} }
} }

View File

@ -20,7 +20,7 @@ public class TFM_ServiceChecker
public final Map<String, TFM_ServiceChecker_ServiceStatus> services = new HashMap<String, TFM_ServiceChecker_ServiceStatus>(); public final Map<String, TFM_ServiceChecker_ServiceStatus> services = new HashMap<String, TFM_ServiceChecker_ServiceStatus>();
public String lastCheck = "Unknown"; public String lastCheck = "Unknown";
public String version = "1.0-Mojang"; public String version = "1.0-Mojang";
public TFM_ServiceChecker() public TFM_ServiceChecker()
{ {
services.put("minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft.net")); services.put("minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft.net"));
@ -32,14 +32,13 @@ public class TFM_ServiceChecker
services.put("session.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Sessions (Legacy)")); services.put("session.minecraft.net", new TFM_ServiceChecker_ServiceStatus("Minecraft Sessions (Legacy)"));
} }
@SuppressWarnings("unchecked")
public BukkitRunnable getUpdateRunnable() public BukkitRunnable getUpdateRunnable()
{ {
return new BukkitRunnable() return new BukkitRunnable()
{ {
@Override @Override
public void run() public void run()
{ {
try try
{ {
@ -58,7 +57,7 @@ public class TFM_ServiceChecker
while (service_it.hasNext()) while (service_it.hasNext())
{ {
Entry<String, String> pair = (Entry<String, String>) service_it.next(); Entry<String, String> pair = (Entry<String, String>) service_it.next();
if ("lastcheck".equals(pair.getKey())) if ("lastcheck".equals(pair.getKey()))
{ {
serviceChecker.lastCheck = pair.getValue(); serviceChecker.lastCheck = pair.getValue();
@ -166,7 +165,7 @@ public class TFM_ServiceChecker
if (!TFM_ServiceChecker.getInstance().version.contains("Mojang")) if (!TFM_ServiceChecker.getInstance().version.contains("Mojang"))
{ {
status += " (" + getUptimeColor() + getUptime() + ChatColor.WHITE + "%)"; status += " (" + getUptimeColor() + getUptime() + ChatColor.WHITE + "%)";
} }
return status; return status;
@ -202,7 +201,5 @@ public class TFM_ServiceChecker
{ {
this.message = message; this.message = message;
} }
} }
} }