crwdns137335:0crwdne137335:0

crwdns137337:0crwdne137337:0

crwdns137339:0crwdne137339:0

crwdns137341:0crwdne137341:0

crwdns137343:0crwdne137343:0

crwdns137345:0crwdne137345:0

import java.math.BigDecimal;

import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.EventContext;
import org.spongepowered.api.event.cause.EventContextKeys;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.Account;

PluginContainer plugin = ...;
EconomyService service = ...;
Account account = ...;
BigDecimal requiredAmount = BigDecimal.valueOf(20);
EventContext eventContext = EventContext.builder().add(EventContextKeys.PLUGIN, plugin).build();

// BAD: Don't perform this check
if (account.getBalance(service.defaultCurrency()).compareTo(requiredAmount) < 0) {
    // You don't have enough money!
} else {
    // The account has enough, let's withdraw some cash!
    account.withdraw(service.defaultCurrency(), requiredAmount, Cause.of(eventContext, plugin));
}

crwdns137347:0:javadoc:crwdnd137347:0:javadoc:crwdnd137347:0:javadoc:crwdnd137347:0:javadoc:crwdne137347:0

crwdns137349:0crwdne137349:0

import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.EventContext;
import org.spongepowered.api.event.cause.EventContextKeys;
import org.spongepowered.api.service.economy.transaction.ResultType;
import org.spongepowered.api.service.economy.transaction.TransactionResult;

PluginContainer plugin = ...;
EconomyService service = ...;
Account account = ...;
BigDecimal requiredAmount = BigDecimal.valueOf(20);
EventContext eventContext = EventContext.builder().add(EventContextKeys.PLUGIN, plugin).build();

TransactionResult result = account.withdraw(service.getDefaultCurrency(), requiredAmount,
                Cause.of(eventContext, plugin));
if (result.result() == ResultType.SUCCESS) {
    // Success!
} else if (result.result() == ResultType.FAILED || result.result() == ResultType.ACCOUNT_NO_FUNDS) {
    // Something went wrong!
} else {
    // Handle other conditions
}