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