crwdns117773:0crwdne117773:0

crwdns117775:0crwdne117775:0

crwdns117777:0crwdne117777:0

crwdns117779:0crwdne117779:0

crwdns117781:0crwdne117781:0

crwdns117783:0crwdne117783: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.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.of(eventContext, plugin));
}

crwdns117785:0:javadoc:crwdnd117785:0:javadoc:crwdnd117785:0:javadoc:crwdnd117785:0:javadoc:crwdne117785:0

crwdns117787:0crwdne117787: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.getResult() == ResultType.SUCCESS) {
    // Success!
} else if (result.getResult() == ResultType.FAILED || result.getResult() == ResultType.ACCOUNT_NO_FUNDS) {
    // Something went wrong!
} else {
    // Handle other conditions
}