Package net.bnubot.core.commands

Examples of net.bnubot.core.commands.CommandFailedWithDetailsException


  public static void setAccountAccess(BNetUser commander, Account commanderAccount, Account subjectAccount, int targetAccess, boolean superUser, boolean whisperBack)
  throws InsufficientAccessException, CommandFailedWithDetailsException {
    Rank originalRank = subjectAccount.getRank();
    int originalAccess = originalRank.getAccess();
    if(targetAccess == originalAccess)
      throw new CommandFailedWithDetailsException("That would have no effect");

    Rank targetRank = Rank.get(targetAccess);
    if(targetRank == null)
      throw new CommandFailedWithDetailsException("Invalid rank: " + targetAccess);

    if(!superUser) {
      if(subjectAccount.equals(commanderAccount))
        throw new InsufficientAccessException("to modify your self", true);

      int commanderAccess = 0;
      if(commanderAccount != null)
        commanderAccess = commanderAccount.getAccess();
      // TODO: get addMax from the database
      int addMax = commanderAccess - 1;
      if(targetAccess > addMax)
        throw new InsufficientAccessException("to add users beyond " + addMax, true);
      if(originalAccess >= commanderAccess)
        throw new InsufficientAccessException("to add users ranked above " + (commanderAccess - 1), true);
    }

    subjectAccount.setRank(targetRank);
    subjectAccount.setLastRankChange(new Date(System.currentTimeMillis()));
    try {
      subjectAccount.updateRow();
      commander.sendChat(subjectAccount.getName() + "'s rank has changed from "
          + originalRank.getPrefix() + " (" + originalAccess + ") to "
          + targetRank.getPrefix() + " (" + targetAccess + ")", whisperBack);
    } catch(Exception e) {
      throw new CommandFailedWithDetailsException(e);
    }
  }
View Full Code Here


      reason = params[1];

    if(isBan && (params[0].indexOf('*') == -1)) {
      BNetUser bnSubject = source.findUser(params[0], user);
      if(!canKickBan(user, bnSubject))
        throw new CommandFailedWithDetailsException("You may not kick or ban users who outrank you.");

      // Regular ban
      String out = (isBan) ? "/ban " : "/kick ";
      if(bnSubject != null)
        out += bnSubject.getFullLogonName();
      else
        out += params[0];
      out += " " + reason;

      // Send the command
      source.sendChat(out);
      setInfoForwarding(source, user, whisperBack);
    } else {
      // Wildcard kick/ban
      Collection<BNetUser> users = source.findUsersWildcard(params[0], user);

      if(users.size() == 0)
        throw new CommandFailedWithDetailsException("That pattern did not match any users.");

      int numSkippedOp = 0;
      int numSkippedOutranked = 0;
      for(BNetUser u : users) {
        if((u.getFlags() & 0x02) != 0) {
View Full Code Here

    }

    BNetUser bnSubject = source.getCreateBNetUser(params[0], user);
    Integer ping = bnSubject.getPing();
    if(ping == null)
      throw new CommandFailedWithDetailsException("I do not know the ping for " + bnSubject.getFullLogonName());
    user.sendChat("Ping for " + bnSubject.getFullLogonName() + ": " + ping, whisperBack);
  }
View Full Code Here

        if(rsSubject == null)
          throw new NeverSeenUserException(bnSubject);

        rsSubjectAccount = rsSubject.getAccount();
        if(rsSubjectAccount == null)
          throw new CommandFailedWithDetailsException("User [" + rsSubject.getLogin() + "] has no account");
      }

      List<String> clauses = new LinkedList<String>();

      // Access
View Full Code Here

    Account rsSubjectAccount = Account.get(params[0]);
    Account targetAccount = Account.get(params[1]);

    if((targetAccount != null) && !targetAccount.equals(rsSubjectAccount))
      throw new CommandFailedWithDetailsException("The Account [" + targetAccount.getName() + "] already exists!");

    if(rsSubjectAccount == null)
      throw new AccountDoesNotExistException(params[0]);

    params[0] = rsSubjectAccount.getName();

    try {
      rsSubjectAccount.setName(params[1]);
      rsSubjectAccount.updateRow();
    } catch(Exception e) {
      throw new CommandFailedWithDetailsException("Rename failed", e);
    }

    user.sendChat("The account [" + params[0] + "] was successfully renamed to [" + params[1] + "]", whisperBack);
  }
View Full Code Here

  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    Vote vote = CommandEventHandler.votes.get(source);
    if(vote == null)
      throw new CommandFailedWithDetailsException("There is no vote in progress");
    else if(commanderAccount == null)
      throw new CommandFailedWithDetailsException("You must have an account to use vote.");
    else if(param.equals("yes"))
      vote.castVote(commanderAccount, true);
    else if(param.equals("no"))
      vote.castVote(commanderAccount, false);
    else
View Full Code Here

        commands = Command.getCommands(commanderAccess);
      else
        commands = Command.getCommands(params[0], commanderAccess);

      if((commands == null) || (commands.size() == 0))
        throw new CommandFailedWithDetailsException("The category [" + params[0] + "] does not exist!");

      StringBuilder result = new StringBuilder("Available commands for rank ");
      result.append(commanderAccess).append(" in cagegory ");
      result.append(params[0]).append(": ");
      boolean first = true;
View Full Code Here

        result += timeElapsed + " days, ";
        result += wins[0] + " wins, ";
        result += wins[1] + " D2 level, ";
        result += wins[2] + " W3 level";

        throw new CommandFailedWithDetailsException(result);
      }

      Integer apDays = rsRank.getApDays();
      Integer apWins = rsRank.getApWins();
      Integer apD2Level = rsRank.getApD2Level();
View Full Code Here

TOP

Related Classes of net.bnubot.core.commands.CommandFailedWithDetailsException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.