Search in sources :

Example 1 with TransactionResult

use of org.spongepowered.api.service.economy.transaction.TransactionResult in project TotalEconomy by Erigitic.

the class TEAccount method resetBalances.

@Override
public Map<Currency, TransactionResult> resetBalances(Cause cause, Set<Context> contexts) {
    TransactionResult transactionResult = new TETransactionResult(this, totalEconomy.getDefaultCurrency(), BigDecimal.ZERO, contexts, ResultType.FAILED, TransactionTypes.WITHDRAW);
    totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
    Map result = new HashMap<>();
    result.put(totalEconomy.getDefaultCurrency(), transactionResult);
    return result;
}
Also used : TransactionResult(org.spongepowered.api.service.economy.transaction.TransactionResult)

Example 2 with TransactionResult

use of org.spongepowered.api.service.economy.transaction.TransactionResult in project TotalEconomy by Erigitic.

the class TEVirtualAccount method resetBalances.

@Override
public Map<Currency, TransactionResult> resetBalances(Cause cause, Set<Context> contexts) {
    TransactionResult transactionResult = new TETransactionResult(this, totalEconomy.getDefaultCurrency(), BigDecimal.ZERO, contexts, ResultType.FAILED, TransactionTypes.WITHDRAW);
    totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
    Map result = new HashMap<>();
    result.put(totalEconomy.getDefaultCurrency(), transactionResult);
    return result;
}
Also used : TransactionResult(org.spongepowered.api.service.economy.transaction.TransactionResult)

Example 3 with TransactionResult

use of org.spongepowered.api.service.economy.transaction.TransactionResult in project TotalEconomy by Erigitic.

the class TEJobManager method startSalaryTask.

/**
     * Start the timer that pays out the salary to each player after a specified time in seconds
     */
private void startSalaryTask() {
    Scheduler scheduler = totalEconomy.getGame().getScheduler();
    Task.Builder payTask = scheduler.createTaskBuilder();
    payTask.execute(() -> {
        for (Player player : totalEconomy.getServer().getOnlinePlayers()) {
            Optional<TEJob> optJob = getJob(getPlayerJob(player), true);
            if (!optJob.isPresent()) {
                player.sendMessage(Text.of(TextColors.RED, "[TE] Cannot pay your salary! Contact your administrator!"));
                return;
            }
            if (optJob.get().salaryEnabled()) {
                BigDecimal salary = optJob.get().getSalary();
                TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
                TransactionResult result = playerAccount.deposit(totalEconomy.getDefaultCurrency(), salary, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
                if (result.getResult() == ResultType.SUCCESS) {
                    player.sendMessage(Text.of(TextColors.GRAY, "Your salary of ", TextColors.GOLD, totalEconomy.getDefaultCurrency().format(salary), TextColors.GRAY, " has just been paid."));
                } else {
                    player.sendMessage(Text.of(TextColors.RED, "[TE] Failed to pay your salary! You may want to contact your admin - TransactionResult: ", result.getResult().toString()));
                }
            }
        }
    }).delay(jobsConfig.getNode("salarydelay").getInt(), TimeUnit.SECONDS).interval(jobsConfig.getNode("salarydelay").getInt(), TimeUnit.SECONDS).name("Pay Day").submit(totalEconomy);
}
Also used : Task(org.spongepowered.api.scheduler.Task) Player(org.spongepowered.api.entity.living.player.Player) TransactionResult(org.spongepowered.api.service.economy.transaction.TransactionResult) Scheduler(org.spongepowered.api.scheduler.Scheduler) TEAccount(com.erigitic.config.TEAccount) BigDecimal(java.math.BigDecimal)

Example 4 with TransactionResult

use of org.spongepowered.api.service.economy.transaction.TransactionResult in project TotalEconomy by Erigitic.

the class TEVirtualAccount method setBalance.

@Override
public TransactionResult setBalance(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    TransactionResult transactionResult;
    String currencyName = currency.getDisplayName().toPlain().toLowerCase();
    if (hasBalance(currency, contexts) && amount.compareTo(BigDecimal.ZERO) >= 0) {
        if (databaseActive) {
            SQLQuery sqlQuery = SQLQuery.builder(sqlHandler.dataSource).update("totaleconomy.accounts").set(currencyName + "_balance").equals(amount.setScale(2, BigDecimal.ROUND_DOWN).toPlainString()).where("uid").equals(identifier).build();
            if (sqlQuery.getRowsAffected() > 0) {
                transactionResult = new TETransactionResult(this, currency, amount, contexts, ResultType.SUCCESS, TransactionTypes.DEPOSIT);
                totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
            } else {
                transactionResult = new TETransactionResult(this, currency, amount, contexts, ResultType.FAILED, TransactionTypes.DEPOSIT);
                totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
            }
            return transactionResult;
        } else {
            accountConfig.getNode(identifier, currencyName + "-balance").setValue(amount.setScale(2, BigDecimal.ROUND_DOWN));
            accountManager.saveAccountConfig();
            transactionResult = new TETransactionResult(this, currency, amount, contexts, ResultType.SUCCESS, TransactionTypes.DEPOSIT);
            totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
            return transactionResult;
        }
    }
    transactionResult = new TETransactionResult(this, currency, amount, contexts, ResultType.ACCOUNT_NO_FUNDS, TransactionTypes.DEPOSIT);
    totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
    return transactionResult;
}
Also used : TransactionResult(org.spongepowered.api.service.economy.transaction.TransactionResult) SQLQuery(com.erigitic.sql.SQLQuery)

Example 5 with TransactionResult

use of org.spongepowered.api.service.economy.transaction.TransactionResult in project TotalEconomy by Erigitic.

the class TEAccount method setBalance.

@Override
public TransactionResult setBalance(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    TransactionResult transactionResult;
    String currencyName = currency.getDisplayName().toPlain().toLowerCase();
    if (hasBalance(currency, contexts) && amount.compareTo(BigDecimal.ZERO) >= 0) {
        if (databaseActive) {
            SQLQuery sqlQuery = SQLQuery.builder(sqlHandler.dataSource).update("totaleconomy.accounts").set(currencyName + "_balance").equals(amount.setScale(2, BigDecimal.ROUND_DOWN).toPlainString()).where("uid").equals(uuid.toString()).build();
            if (sqlQuery.getRowsAffected() > 0) {
                transactionResult = new TETransactionResult(this, currency, amount, contexts, ResultType.SUCCESS, TransactionTypes.DEPOSIT);
                totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
            } else {
                transactionResult = new TETransactionResult(this, currency, amount, contexts, ResultType.FAILED, TransactionTypes.DEPOSIT);
                totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
            }
            return transactionResult;
        } else {
            accountConfig.getNode(uuid.toString(), currencyName + "-balance").setValue(amount.setScale(2, BigDecimal.ROUND_DOWN));
            accountManager.saveAccountConfig();
            transactionResult = new TETransactionResult(this, currency, amount, contexts, ResultType.SUCCESS, TransactionTypes.DEPOSIT);
            totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
            return transactionResult;
        }
    }
    transactionResult = new TETransactionResult(this, currency, amount, contexts, ResultType.ACCOUNT_NO_FUNDS, TransactionTypes.DEPOSIT);
    totalEconomy.getGame().getEventManager().post(new TEEconomyTransactionEvent(transactionResult));
    return transactionResult;
}
Also used : TransactionResult(org.spongepowered.api.service.economy.transaction.TransactionResult) SQLQuery(com.erigitic.sql.SQLQuery)

Aggregations

TransactionResult (org.spongepowered.api.service.economy.transaction.TransactionResult)6 TEAccount (com.erigitic.config.TEAccount)2 SQLQuery (com.erigitic.sql.SQLQuery)2 BigDecimal (java.math.BigDecimal)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CommandException (org.spongepowered.api.command.CommandException)1 Player (org.spongepowered.api.entity.living.player.Player)1 User (org.spongepowered.api.entity.living.player.User)1 Scheduler (org.spongepowered.api.scheduler.Scheduler)1 Task (org.spongepowered.api.scheduler.Task)1 Text (org.spongepowered.api.text.Text)1