예제 #1
0
  private void toggleTimings(CommandSender sender, String[] args) {
    TimedListenerManager manager = TimedListenerManager.getInstance();
    boolean state = !manager.isTiming(); // toggle

    // Parse the boolean parameter
    if (args.length == 2) {
      Boolean parsed = parseBoolean(toQueue(args, 2), "start");

      if (parsed != null) {
        state = parsed;
      } else {
        sender.sendMessage(ChatColor.RED + "Specify a state: ON or OFF.");
        return;
      }
    } else if (args.length > 2) {
      sender.sendMessage(ChatColor.RED + "Too many parameters.");
      return;
    }

    // Now change the state
    if (state) {
      if (manager.startTiming())
        sender.sendMessage(ChatColor.GOLD + "Started timing packet listeners.");
      else sender.sendMessage(ChatColor.RED + "Packet timing already started.");
    } else {
      if (manager.stopTiming()) {
        saveTimings(manager);
        sender.sendMessage(ChatColor.GOLD + "Stopped and saved result in plugin folder.");
      } else {
        sender.sendMessage(ChatColor.RED + "Packet timing already stopped.");
      }
    }
  }
예제 #2
0
  private void saveTimings(TimedListenerManager manager) {
    try {
      File destination =
          new File(plugin.getDataFolder(), "Timings - " + System.currentTimeMillis() + ".txt");
      TimingReportGenerator generator = new TimingReportGenerator();

      // Print to a text file
      generator.saveTo(destination, manager);
      manager.clear();
    } catch (IOException e) {
      reporter.reportMinimal(plugin, "saveTimings()", e);
    }
  }