Search in sources :

Example 1 with MoneyChangeEvent

use of com.nextplugins.economy.api.event.operations.MoneyChangeEvent 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)

Example 2 with MoneyChangeEvent

use of com.nextplugins.economy.api.event.operations.MoneyChangeEvent in project NextEconomy by NextPlugins.

the class MoneySetListener method onSet.

@EventHandler(priority = EventPriority.MONITOR)
public void onSet(MoneySetEvent event) {
    if (event.isCancelled())
        return;
    val sender = event.getSender();
    val target = event.getTarget();
    val amount = event.getAmount();
    val targetAccount = accountStorage.findAccount(target);
    if (targetAccount == null) {
        sender.sendMessage(MessageValue.get(MessageValue::invalidTarget));
        return;
    }
    if (Double.isNaN(amount) || amount < 1) {
        sender.sendMessage(MessageValue.get(MessageValue::invalidMoney));
        return;
    }
    targetAccount.setBalance(amount);
    sender.sendMessage(MessageValue.get(MessageValue::setAmount).replace("$player", target.getName()).replace("$amount", NumberUtils.format(amount)));
    if (!target.isOnline())
        return;
    val player = target.getPlayer();
    val moneyChangeEvent = new MoneyChangeEvent(player, targetAccount, targetAccount.getBalance(), targetAccount.getBalanceFormated());
    Bukkit.getPluginManager().callEvent(moneyChangeEvent);
}
Also used : lombok.val(lombok.val) MoneyChangeEvent(com.nextplugins.economy.api.event.operations.MoneyChangeEvent) EventHandler(org.bukkit.event.EventHandler)

Example 3 with MoneyChangeEvent

use of com.nextplugins.economy.api.event.operations.MoneyChangeEvent in project NextEconomy by NextPlugins.

the class MoneyCommand method moneyResetCommand.

@Command(name = "coins.reset", aliases = { "zerar", "resetar" }, usage = "/coins reset {jogador}", description = "Utilize para zerar a quantia de dinheiro de alguém.", permission = "nexteconomy.command.reset")
public void moneyResetCommand(Context<CommandSender> context, OfflinePlayer target) {
    val sender = context.getSender();
    val offlineAccount = accountStorage.findAccount(target);
    if (offlineAccount == null) {
        sender.sendMessage(MessageValue.get(MessageValue::invalidTarget));
        return;
    }
    offlineAccount.setBalance(0);
    offlineAccount.setMovimentedBalance(0);
    offlineAccount.setTransactions(Lists.newLinkedList());
    offlineAccount.setTransactionsQuantity(0);
    sender.sendMessage(MessageValue.get(MessageValue::resetBalance).replace("$player", target.getName()));
    if (!target.isOnline())
        return;
    val player = target.getPlayer();
    val moneyChangeEvent = new MoneyChangeEvent(player, offlineAccount, offlineAccount.getBalance(), offlineAccount.getBalanceFormated());
    Bukkit.getPluginManager().callEvent(moneyChangeEvent);
}
Also used : lombok.val(lombok.val) MessageValue(com.nextplugins.economy.configuration.MessageValue) MoneyChangeEvent(com.nextplugins.economy.api.event.operations.MoneyChangeEvent) Command(me.saiintbrisson.minecraft.command.annotation.Command)

Aggregations

MoneyChangeEvent (com.nextplugins.economy.api.event.operations.MoneyChangeEvent)3 lombok.val (lombok.val)2 MessageValue (com.nextplugins.economy.configuration.MessageValue)1 BankHistoricComparator (com.nextplugins.economy.model.account.historic.BankHistoricComparator)1 Command (me.saiintbrisson.minecraft.command.annotation.Command)1 EconomyResponse (net.milkbowl.vault.economy.EconomyResponse)1 EventHandler (org.bukkit.event.EventHandler)1