/**
   * @see
   *     org.alfresco.contentcraft.command.BaseCommandExecuter#onCommandImpl(org.bukkit.command.CommandSender,
   *     org.bukkit.command.Command, java.lang.String, java.lang.String[])
   */
  @Override
  public void onCommandImpl(CommandSender sender, Command command, String label, String[] args)
      throws CommandUsageException {
    String operation = args[0];
    if (operation.equalsIgnoreCase(CMD_LIST)) {
      StringBuilder builder = new StringBuilder("Available macros:\n");
      for (String name : macros.keySet()) {
        builder.append("  - " + name + "\n");
      }
      sender.sendMessage(builder.toString());

      // temp
      save();
    } else if (operation.equalsIgnoreCase(CMD_STOP)) {
      // stop recording the currently recording macro
      if (recordingMacro != null) {
        recordingMacro.stop();
        recordingMacro = null;
        save();
      } else {
        for (Macro macro : macros.values()) {
          macro.stop();
        }
      }
    } else {
      String name = args[1];
      Macro macro = macros.get(name);

      if (operation.equalsIgnoreCase(CMD_START)) {
        if (recordingMacro == null) {
          if (macro == null) {
            macro = Macro.startNew(name);
            macros.put(name, macro);
          } else {
            macro.clear();
            macro.start();
          }

          // store the currently recording macro
          recordingMacro = macro;
        } else {
          // a macro is already recording
          sender.sendMessage(
              "Can't start macro, because "
                  + recordingMacro.getName()
                  + " is currently being recorded.");
        }
      } else if (operation.equalsIgnoreCase(CMD_RUN)) {
        if (macro != null) {
          boolean runRepeat = false;

          if (args.length == 3 && "-R".equals(args[2])) {
            runRepeat = true;
          }

          macro.runPending(runRepeat);
        }
      } else if (operation.equalsIgnoreCase(CMD_DELETE)) {
        if (macro != null) {
          macros.remove(name);
          save();
        }
      }
    }
  }