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.");
}
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);
}
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);
}
Aggregations