Search in sources :

Example 1 with BankHistoricComparator

use of com.nextplugins.economy.model.account.historic.BankHistoricComparator in project NextEconomy by NextPlugins.

the class Account method createTransaction.

public synchronized EconomyResponse createTransaction(@NotNull Transaction transaction) {
    val amount = transaction.amount();
    if (NumberUtils.isInvalid(amount)) {
        return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.FAILURE, "O valor inserido é inválido.");
    }
    val transactionType = transaction.transactionType();
    if (transactionType == TransactionType.WITHDRAW) {
        if (!hasAmount(amount)) {
            return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.FAILURE, "Não foi possível terminar esta operação. " + "(A conta requisitada não possui quantia suficiente para completar esta transação).");
        }
        movimentedBalance += amount;
        this.balance -= amount;
    } else
        this.balance += amount;
    if (this.balance < 0)
        this.balance = 0;
    if (transaction.owner() != null) {
        ++transactionsQuantity;
        val historic = AccountBankHistoric.builder().target(transaction.owner()).amount(amount).type(transactionType).build();
        if (transactions.size() >= 56)
            transactions.remove(0);
        transactions.add(historic);
        transactions.sort(new BankHistoricComparator());
        save();
    } else {
        fastSave();
    }
    increaseData(transactionType);
    val player = transaction.player();
    if (player != null) {
        val moneyChangeEvent = new MoneyChangeEvent(player, this, balance, NumberUtils.format(balance));
        Bukkit.getScheduler().runTask(NextEconomy.getInstance(), () -> Bukkit.getPluginManager().callEvent(moneyChangeEvent));
        val isInBlockedWorld = PurseValue.get(PurseValue::worlds).contains(player.getWorld().getName());
        val amountWithoutPurse = transaction.amountWithoutPurse();
        if (amountWithoutPurse > 0 && amount != amountWithoutPurse && !isInBlockedWorld) {
            MessageUtil.sendPurseAffectMessage(transaction);
        }
    }
    return new EconomyResponse(amount, balance, EconomyResponse.ResponseType.SUCCESS, "Operação realizada com sucesso.");
}
Also used : BankHistoricComparator(com.nextplugins.economy.model.account.historic.BankHistoricComparator) EconomyResponse(net.milkbowl.vault.economy.EconomyResponse) MoneyChangeEvent(com.nextplugins.economy.api.event.operations.MoneyChangeEvent)

Aggregations

MoneyChangeEvent (com.nextplugins.economy.api.event.operations.MoneyChangeEvent)1 BankHistoricComparator (com.nextplugins.economy.model.account.historic.BankHistoricComparator)1 EconomyResponse (net.milkbowl.vault.economy.EconomyResponse)1