Пример #1
0
  @Override
  public EconomyResponse depositPlayer(String playerName, double amount) {
    double balance;
    EconomyResponse.ResponseType type;
    String errorMessage = null;

    if (amount < 0) {
      errorMessage = "Cannot deposit negative funds";
      type = EconomyResponse.ResponseType.FAILURE;
      amount = 0;
      balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName);

      return new EconomyResponse(amount, balance, type, errorMessage);
    }

    if (CurrencyList.add(playerName, amount)) {
      type = EconomyResponse.ResponseType.SUCCESS;
      balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName);

      return new EconomyResponse(amount, balance, type, errorMessage);
    } else {
      errorMessage = "Error withdrawing funds";
      type = EconomyResponse.ResponseType.FAILURE;
      amount = 0;
      balance = CurrencyList.getValue((String) CurrencyList.maxCurrency(playerName)[0], playerName);

      return new EconomyResponse(amount, balance, type, errorMessage);
    }
  }