Пример #1
0
 @Override
 public boolean transfer(String playerFrom, String playerTo, double amount) {
   checkExist(playerTo);
   checkExist(playerFrom);
   if (this.canAfford(playerFrom, amount)) {
     Account p1 = new Accounts().get(playerFrom);
     Account p2 = new Accounts().get(playerTo);
     p1.getHoldings().subtract(amount);
     p2.getHoldings().add(amount);
     return true;
   }
   return false;
 }
Пример #2
0
  @Override
  public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments)
      throws InvalidUsage {
    if (!hasPermissions(sender, "take")) {
      template.noPermission(sender);
      return false;
    }

    String name = arguments.get("name").getStringValue();
    String tag = template.color(Template.Node.TAG_MONEY);
    Double amount;

    if (name.equals("0"))
      throw new InvalidUsage("Missing name parameter: /money take <name> <amount>");

    if (arguments.get("amount").getStringValue().equals("empty"))
      throw new InvalidUsage("Missing amount parameter: /money take <name> <amount>");

    try {
      amount = arguments.get("amount").getDoubleValue();
    } catch (NumberFormatException e) {
      throw new InvalidUsage("Invalid amount parameter, must be double.");
    }

    if (Double.isInfinite(amount) || Double.isNaN(amount))
      throw new InvalidUsage("Invalid amount parameter, must be double.");

    if (!Accounts.exists(name)) {
      template.set(Template.Node.ERROR_ACCOUNT);
      template.add("name", name);

      Messaging.send(sender, tag + template.parse());
      return false;
    }

    Account account = new Account(name);
    account.getHoldings().subtract(amount);

    template.set(Template.Node.PLAYER_DEBIT);
    template.add("name", name);
    template.add("amount", iConomy.format(amount));

    Messaging.send(sender, tag + template.parse());
    return false;
  }
Пример #3
0
 public iCoAccount(Account account) {
   this.account = account;
   this.holdings = account.getHoldings();
 }