Search in sources :

Example 6 with SQLQuery

use of com.erigitic.sql.SQLQuery 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 7 with SQLQuery

use of com.erigitic.sql.SQLQuery 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

SQLQuery (com.erigitic.sql.SQLQuery)7 IOException (java.io.IOException)3 TransactionResult (org.spongepowered.api.service.economy.transaction.TransactionResult)2 UUID (java.util.UUID)1