/**
   * Return all classes which extend our Command interface.
   *
   * @return
   */
  private Set<Class<? extends Command>> getCommandClasses() {
    if (commandClasses != null) return commandClasses;

    commandClasses = reflections.getSubTypesOf(Command.class);
    Set<Class<? extends BaseCommand>> baseCommandClasses =
        reflections.getSubTypesOf(BaseCommand.class);
    for (Class<? extends BaseCommand> bc : baseCommandClasses) {
      commandClasses.add((Class<? extends Command>) bc);
    }

    if (commandClasses == null || commandClasses.size() == 0) {
      log.severe("No command classes found, HSP will not be able to register commands!");
    }

    return commandClasses;
  }
  /**
   * Given a class file (which must be of our Command interface), register that Command with Bukkit.
   *
   * @param clazz
   */
  private void registerDefaultCommand(Class<? extends Command> clazz) {
    try {
      Debug.getInstance().devDebug("registering command class ", clazz);
      Command cmd = (Command) clazz.newInstance();

      String cmdName = cmd.getCommandName();
      // do nothing if the command is disabled
      if (commandConfig.isDisabledCommand(cmdName)) {
        log.debug(
            "registerDefaultCommand() skipping ", cmdName, " because it is flagged as disabled");
        return;
      }

      register(cmd);
    } catch (Exception e) {
      log.severe(e, "error trying to load command class " + clazz);
    }
  }
  /**
   * Given a commandName, find the default command which matches.
   *
   * @param cmdName
   * @return
   */
  private Class<? extends Command> findDefaultCommand(String cmdName) {
    Set<Class<? extends Command>> classes = getCommandClasses();

    for (Class<? extends Command> clazz : classes) {
      try {
        Command cmd = (Command) clazz.newInstance();
        if (cmd.getCommandName().equals(cmdName)) return clazz;

        String[] aliases = cmd.getCommandAliases();
        if (aliases != null && aliases.length > 0) {
          for (String alias : aliases) {
            if (alias.equals(cmdName)) return clazz;
          }
        }
      } catch (Exception e) {
        log.severe(e, "Caught exception in findDefaultCommand for command " + cmdName);
      }
    }

    return null;
  }