crwdns147979:0crwdne147979:0

crwdns147981:0crwdne147981:0

crwdns147983:0crwdne147983:0

crwdns147985:0crwdne147985:0

crwdns147987:0crwdne147987:0

crwdns147989:0crwdne147989: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());
}

crwdns147991:0:javadoc:crwdnd147991:0:javadoc:crwdnd147991:0:javadoc:crwdnd147991:0:javadoc:crwdne147991:0

crwdns147993:0crwdne147993: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
}