コード例 #1
0
  /**
   * Removes an amount from the specified player's balance. Checks if the player has a balance
   * greater then or equal to the amount being removed.
   *
   * @param uuid object representing the UUID of a player
   * @param amount amount to be removed from balance
   */
  @Override
  public void removeFromBalance(UUID uuid, BigDecimal amount) {
    if (hasAccount(uuid)) {
      BigDecimal newBalance =
          new BigDecimal(getBalance(uuid).toString()).subtract(new BigDecimal(amount.toString()));

      try {
        accountConfig
            .getNode(uuid.toString(), "balance")
            .setValue(newBalance.setScale(2, BigDecimal.ROUND_DOWN).toString());
        configManager.save(accountConfig);

        server
            .getPlayer(uuid)
            .get()
            .sendMessage(
                Texts.of(
                    TextColors.GOLD,
                    totalEconomy.getCurrencySymbol(),
                    amount,
                    TextColors.GRAY,
                    " has been removed from your balance."));
      } catch (IOException e) {
        logger.warn("Could not remove from player balance!");
      }
    }
  }
コード例 #2
0
  /**
   * Checks if the player has enough money in there balance to remove from.
   *
   * @param uuid object representing the UUID of a player
   * @param amount amount to be checked
   * @return boolean weather or not the player has enough money in balance
   */
  @Override
  public boolean hasMoney(UUID uuid, BigDecimal amount) {
    BigDecimal balance = getBalance(uuid);

    int result = amount.compareTo(balance);

    if (result == -1 || result == 0) return true;
    else server.getPlayer(uuid).get().sendMessage(Texts.of(TextColors.RED, "Insufficient funds."));

    return false;
  }