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;
}
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;
}
Aggregations