Пример #1
0
 @Override
 public void log(String message) {
   message = C.format(message, C.replacements);
   if (!Settings.CONSOLE_COLOR) {
     message = message.replaceAll('\u00a7' + "[a-z|0-9]", "");
   }
   if (server == null || server.getConsole() == null) {
     logger.info(message);
     return;
   }
   server.getConsole().sendMessage(Texts.of(message));
 }
Пример #2
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!");
      }
    }
  }
Пример #3
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;
  }