Fixed typos and add usage message to timings command.

By: Travis Watkins <amaranth@ubuntu.com>
This commit is contained in:
Bukkit/Spigot 2012-02-10 13:48:53 -06:00
parent a66baab794
commit b7a973b822

View File

@ -1,6 +1,7 @@
package org.bukkit.command.defaults; package org.bukkit.command.defaults;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -12,27 +13,28 @@ import org.bukkit.plugin.TimedRegisteredListener;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class TimingsCommand extends Command { public class TimingsCommand extends Command {
public TimingsCommand(String name) { public TimingsCommand(String name) {
super(name); super(name);
this.description = "Records timings for all plugin events"; this.description = "Records timings for all plugin events";
this.usageMessage = "/timings <function>"; this.usageMessage = "/timings <reset|merged|separate>";
this.setPermission("bukkit.command.timings"); this.setPermission("bukkit.command.timings");
} }
@Override @Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) { public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true; if (!testPermission(sender)) return true;
if (args.length != 1) return false; if (args.length != 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
if (!sender.getServer().getPluginManager().useTimings()) { if (!sender.getServer().getPluginManager().useTimings()) {
sender.sendMessage("Please enable timings by setting \"settings.plugin-profiling\" to true in bukkit.yml"); sender.sendMessage("Please enable timings by setting \"settings.plugin-profiling\" to true in bukkit.yml");
return true; return true;
} }
boolean seperate = "seperate".equals(args[0]); boolean separate = "separate".equals(args[0]);
if ("reset".equals(args[0])) { if ("reset".equals(args[0])) {
for (HandlerList handlerList : HandlerList.getHandlerLists()) { for (HandlerList handlerList : HandlerList.getHandlerLists()) {
for (RegisteredListener[] listeners : handlerList.getRegisteredListeners()) { for (RegisteredListener[] listeners : handlerList.getRegisteredListeners()) {
@ -44,7 +46,7 @@ public class TimingsCommand extends Command {
} }
} }
sender.sendMessage("Timings reset"); sender.sendMessage("Timings reset");
} else if ("merged".equals(args[0]) || seperate) { } else if ("merged".equals(args[0]) || separate) {
int index = 0; int index = 0;
int pluginIdx = 0; int pluginIdx = 0;
@ -52,18 +54,18 @@ public class TimingsCommand extends Command {
timingFolder.mkdirs(); timingFolder.mkdirs();
File timings = new File(timingFolder, "timings.txt"); File timings = new File(timingFolder, "timings.txt");
File names = null; File names = null;
while (timings.exists()) timings = new File(timingFolder, "timinigs" + (++index) + ".txt"); while (timings.exists()) timings = new File(timingFolder, "timings" + (++index) + ".txt");
try { try {
PrintStream fileTimings = new PrintStream(timings); PrintStream fileTimings = new PrintStream(timings);
PrintStream fileNames = null; PrintStream fileNames = null;
if (seperate) { if (separate) {
names = new File(timingFolder, "names" + index + ".txt"); names = new File(timingFolder, "names" + index + ".txt");
fileNames = new PrintStream(names); fileNames = new PrintStream(names);
} }
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
pluginIdx++; pluginIdx++;
long totalTime = 0; long totalTime = 0;
if (seperate) { if (separate) {
fileNames.println(pluginIdx + " " + plugin.getDescription().getFullName()); fileNames.println(pluginIdx + " " + plugin.getDescription().getFullName());
fileTimings.println("Plugin " + pluginIdx); fileTimings.println("Plugin " + pluginIdx);
} }
@ -85,7 +87,7 @@ public class TimingsCommand extends Command {
fileTimings.println(" Total time " + totalTime + " (" + totalTime / 1000000000 + "s)"); fileTimings.println(" Total time " + totalTime + " (" + totalTime / 1000000000 + "s)");
} }
sender.sendMessage("Timings written to " + timings.getPath()); sender.sendMessage("Timings written to " + timings.getPath());
if (seperate) sender.sendMessage("Names written to " + names.getPath()); if (separate) sender.sendMessage("Names written to " + names.getPath());
} catch (IOException e) { } catch (IOException e) {
} }
} }