Exemple #1
0
  /**
   * Handle a command.
   *
   * @param user UserSocket that issued the command
   * @param params Params for command (param0 is the command name)
   * @param output CommandOutputBuffer where output from this command should go.
   * @throws CommandNotFoundException exception if no commands exists to handle the line
   */
  public void handle(final UserSocket user, final String[] params, final CommandOutputBuffer output)
      throws CommandNotFoundException {
    if (params.length == 0 || params[0] == null || params[0].isEmpty()) {
      throw new CommandNotFoundException("No valid command given.");
    }

    final Optional<Entry<String, Command>> e =
        getMatchingCommand(params[0], user.getAccount().isAdmin());
    if (!e.isPresent()) {
      throw new CommandNotFoundException("Command not found: " + params[0]);
    }

    String[] handleParams = params;
    handleParams[0] = e.get().getKey();
    final Command commandHandler = e.get().getValue();

    try {
      if (commandHandler.isAdminOnly() && !user.getAccount().isAdmin()) {
        throw new CommandNotFoundException("No command is known by " + params[0]);
      } else {
        commandHandler.handle(user, handleParams, output);
      }
    } catch (Exception ex) {
      Logger.error("There has been an error with the command '" + params[0] + "'");
      ex.printStackTrace();
    }
  }
 @Override
 public Config getConfig(final UserSocket user, final String sublist) {
   return user.getAccount().getConfig(sublist);
 }