crwdns128753:0crwdne128753:0
crwdns128755:0crwdne128755:0
crwdns128757:0crwdne128757:0
crwdns128759:0crwdne128759:0
crwdns128761:0crwdne128761:0
crwdns128763:0crwdne128763:0
import java.math.BigDecimal;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.Account;
EconomyService service = ...;
Account account = ...;
BigDecimal requiredAmount = BigDecimal.valueOf(20);
// BAD: Don't perform this check
if (account.getBalance(service.getDefaultCurrency()).compareTo(requiredAmount) < 0) {
// You don't have enough money!
} else {
// The account has enough, let's withdraw some cash!
account.withdraw(service.getDefaultCurrency(), requiredAmount,
Cause.source(this).build());
}
crwdns128765:0:javadoc:crwdnd128765:0:javadoc:crwdnd128765:0:javadoc:crwdnd128765:0:javadoc:crwdne128765:0
crwdns128767:0crwdne128767:0
import org.spongepowered.api.service.economy.transaction.ResultType;
import org.spongepowered.api.service.economy.transaction.TransactionResult;
EconomyService service = ...
Account account = ...
BigDecimal requiredAmount = BigDecimal.valueOf(20);
TransactionResult result = account.withdraw(service.getDefaultCurrency(),
requiredAmount, Cause.source(this).build());
if (result.getResult() == ResultType.SUCCESS)) {
// Success!
} else if (result.getResult() == ResultType.FAILED || result.getResult() == ResultType.ACCOUNT_NO_FUNDS) {
// Something went wrong!
} else {
// Handle other conditions
}