コード例 #1
0
ファイル: CostHandler.java プロジェクト: Nu11u5/Stargate
  public CostHandler(String cost) {
    method = PaymentMethod.Blocks;

    ArrayList<Item> array = new ArrayList<Item>();
    Matcher matcher = regex.matcher(cost);

    while (matcher.find()) {
      int amount = 1;
      int itemid = etc.getDataSource().getItem(matcher.group(2));

      if (itemid == 0) {
        try {
          itemid = Integer.parseInt(matcher.group(2));
        } catch (NumberFormatException ex) {
          Stargate.log(
              Level.WARNING,
              ex.getMessage() + " while parsing block payment string - no such block exists?");
          continue;
        }
      }

      if ((matcher.group(1) != null) && (!matcher.group(1).isEmpty())) {
        try {
          amount = Integer.parseInt(matcher.group(1));
        } catch (NumberFormatException ex) {
          amount = 1;
          Stargate.log(Level.WARNING, ex.getMessage() + " while parsing block payment string");
        }
      }

      array.add(new Item(itemid, amount));
    }

    items = array.toArray(items);
  }
コード例 #2
0
ファイル: CostHandler.java プロジェクト: Nu11u5/Stargate
  public CostHandler(String cost, String moneyDest) {
    method = PaymentMethod.iConomy;
    destination = moneyDest;

    try {
      money = Integer.parseInt(cost);
    } catch (NumberFormatException ex) {
      money = 0;
      Stargate.log(Level.WARNING, ex.getMessage() + " while parsing iConomy payment");
    }
  }
コード例 #3
0
ファイル: CostHandler.java プロジェクト: Nu11u5/Stargate
  private boolean deductIConomy(Player player) {
    if (!iData.iExist()) {
      Stargate.log(Level.WARNING, "iConomy payment selected but iConomy does not exist");
      return true;
    }

    if (money > 0) {
      iData icon = new iData();
      int balance = icon.getBalance(player.getName());
      String deducted = icon.settings.getString("money-deducted", "");
      String coin = icon.settings.getString("money-name", "");
      String receive = icon.settings.getString("money-receive", "");

      if (balance >= money) {
        String[] recipient = destination.split(" ", 2);
        icon.setBalance(player.getName(), balance - money);
        if (!deducted.isEmpty()) player.sendMessage(String.format(deducted, money + coin));

        if ((recipient.length > 0) && (recipient[0].equalsIgnoreCase("player"))) {
          if ((recipient.length > 1) && (icon.hasBalance(recipient[1]))) {
            balance = icon.getBalance(recipient[1]);
            icon.setBalance(recipient[1], balance + money);

            if (!receive.isEmpty()) player.sendMessage(String.format(receive, money + coin));
          } else {
            Stargate.log(
                Level.WARNING,
                "cost-destination set to player but specified player does not exist or was not defined");
          }
        }

        return true;
      } else {
        return false;
      }
    }

    return true;
  }