Interface Account
-
- All Superinterfaces:
Contextual
- All Known Subinterfaces:
UniqueAccount,VirtualAccount
public interface Account extends Contextual
Represents an account, which stores amounts of variouscurrencies.Accounts come in two varieties:
user accountsandVirtualAccountvirtual accounts. Unique accounts are bound to aUUID, usually of a particularUser'sGameProfile. Virtual accounts are identified by a String identifier, which may have any value. They are not tied to anyEntity, player or otherwise. Virtual accounts may be used for purposes such as bank accounts, non-playerEntityaccounts, or other things.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default BigDecimalbalance(Currency currency)Returns aBigDecimalrepresentative of the balance stored within thisAccountfor theCurrencygiven, with the current active cause.BigDecimalbalance(Currency currency, Set<Context> contexts)Returns aBigDecimalrepresentative of the balance stored within thisAccountfor theCurrencygiven and the set ofContexts.BigDecimalbalance(Currency currency, Cause cause)Returns aBigDecimalrepresentative of the balance stored within thisAccountfor theCurrencygiven and the set ofContexts.default Map<Currency,BigDecimal>balances()Map<Currency,BigDecimal>balances(Set<Context> contexts)Map<Currency,BigDecimal>balances(Cause cause)BigDecimaldefaultBalance(Currency currency)Gets the default balance of this account for the specifiedCurrency.default TransactionResultdeposit(Currency currency, BigDecimal amount)TransactionResultdeposit(Currency currency, BigDecimal amount, Set<Context> contexts)TransactionResultdeposit(Currency currency, BigDecimal amount, Cause cause)ComponentdisplayName()Gets the display name for this account.default booleanhasBalance(Currency currency)Returns whether this account has a set balance for the specifiedCurrency, with the current active cause.booleanhasBalance(Currency currency, Set<Context> contexts)booleanhasBalance(Currency currency, Cause cause)default TransactionResultresetBalance(Currency currency)Resets the balance for the specifiedCurrencyto its default value (defaultBalance(Currency)), using the current activeContexts.TransactionResultresetBalance(Currency currency, Set<Context> contexts)Resets the balance for the specifiedCurrencyto its default value (defaultBalance(Currency)), using the specifiedContexts.TransactionResultresetBalance(Currency currency, Cause cause)Resets the balance for the specifiedCurrencyto its default value (defaultBalance(Currency)), using context from the specifiedCause.default Map<Currency,TransactionResult>resetBalances()Resets the balances for allCurrencys used on this account to their default values (defaultBalance(Currency)), using the current activeContext.Map<Currency,TransactionResult>resetBalances(Set<Context> contexts)Resets the balances for allCurrencys used on this account to their default values (defaultBalance(Currency)), using the specifiedContexts.Map<Currency,TransactionResult>resetBalances(Cause cause)Resets the balances for allCurrencys used on this account to their default values (defaultBalance(Currency)), using the specifiedCauses.default TransactionResultsetBalance(Currency currency, BigDecimal amount)TransactionResultsetBalance(Currency currency, BigDecimal amount, Set<Context> contexts)TransactionResultsetBalance(Currency currency, BigDecimal amount, Cause cause)default TransferResulttransfer(Account to, Currency currency, BigDecimal amount)TransferResulttransfer(Account to, Currency currency, BigDecimal amount, Set<Context> contexts)TransferResulttransfer(Account to, Currency currency, BigDecimal amount, Cause cause)default TransactionResultwithdraw(Currency currency, BigDecimal amount)TransactionResultwithdraw(Currency currency, BigDecimal amount, Set<Context> contexts)TransactionResultwithdraw(Currency currency, BigDecimal amount, Cause cause)-
Methods inherited from interface org.spongepowered.api.service.context.Contextual
contextCause, friendlyIdentifier, identifier
-
-
-
-
Method Detail
-
displayName
Component displayName()
Gets the display name for this account.This should be used by plugins to get a human-readable name for an account, regardless of the specific type (
UniqueAccountorVirtualAccount).Its contents are dependent on the provider of
.EconomyService. For example, an economy plugin could allow players to configure the display name of their account- Returns:
- The display name for this account
-
defaultBalance
BigDecimal defaultBalance(Currency currency)
Gets the default balance of this account for the specifiedCurrency.The default balance is used when the balance is retrieved for the first time for a given
Currencyon this account, or if no balance is available for theContexts used when retrieving a balance.- Parameters:
currency- the currency to get the default balance for.- Returns:
- The default balance for the specified
Currency.
-
hasBalance
boolean hasBalance(Currency currency, Set<Context> contexts)
Returns whether this account has a set balance for the specifiedCurrency, with the specifiedContexts.If this method returns
false, thendefaultBalance(Currency)will be used when retrieving a balance for the specifiedCurrencywith the specifiedContexts.
-
hasBalance
boolean hasBalance(Currency currency, Cause cause)
Returns whether this account has a set balance for the specifiedCurrency, with context from the specifiedCauses.If this method returns
false, thendefaultBalance(Currency)will be used when retrieving a balance for the specifiedCurrencywith the specifiedContexts.
-
hasBalance
default boolean hasBalance(Currency currency)
Returns whether this account has a set balance for the specifiedCurrency, with the current active cause.If this method returns
.false, thendefaultBalance(Currency)will be used when retrieving a balance for the specifidCurrencywith the current active cause
-
balance
BigDecimal balance(Currency currency, Set<Context> contexts)
Returns aBigDecimalrepresentative of the balance stored within thisAccountfor theCurrencygiven and the set ofContexts.The default result when the account does not have a balance of the given
Currencywill bedefaultBalance(Currency).The balance may be unavailable depending on the set of
Contexts used.
-
balance
BigDecimal balance(Currency currency, Cause cause)
Returns aBigDecimalrepresentative of the balance stored within thisAccountfor theCurrencygiven and the set ofContexts.The default result when the account does not have a balance of the given
Currencywill bedefaultBalance(Currency).The balance may be unavailable depending on the set of
Contexts used.
-
balance
default BigDecimal balance(Currency currency)
Returns aBigDecimalrepresentative of the balance stored within thisAccountfor theCurrencygiven, with the current active cause.The default result when the account does not have a balance of the given
Currencywill bedefaultBalance(Currency).
-
balances
Map<Currency,BigDecimal> balances(Set<Context> contexts)
Returns aMapof all currently set balances the account holds within the set ofContexts.Amounts may differ depending on the
Contexts specified and the implementation. The set ofContexts may be empty.Currencyamounts which are 0 may or may not be included in the returned mapping.Changes to the returned
Mapwill not be reflected in the underlyingAccount. SeesetBalance(Currency, BigDecimal, Cause)to set values.- Parameters:
contexts- the set ofContexts to use with the specified amounts- Returns:
- A
MapofCurrencytoBigDecimalamounts that this account holds
-
balances
Map<Currency,BigDecimal> balances(Cause cause)
Returns aMapof all currently set balances the account holds within the set ofContexts.Amounts may differ depending on the
Causespecified and the implementation. The set ofContexts may be empty.Currencyamounts which are 0 may or may not be included in the returned mapping.Changes to the returned
Mapwill not be reflected in the underlyingAccount. SeesetBalance(Currency, BigDecimal, Cause)to set values.- Parameters:
cause- the set ofContexts to use with the specified amounts- Returns:
- A
MapofCurrencytoBigDecimalamounts that this account holds
-
balances
default Map<Currency,BigDecimal> balances()
Returns aMapof all currently set balances the account holds within the current activeContext.Amounts may differ depending on the
Contexts specified and the implementation. The set ofContexts may be empty.Currencyamounts which are 0 may or may not be included in the returned mapping.Changes to the returned
Mapwill not be reflected in the underlyingAccountand may result in runtime exceptions depending on implementation. SeesetBalance(Currency, BigDecimal, Cause)to set values.- Returns:
- A
MapofCurrencytoBigDecimalamounts that this account holds
-
setBalance
TransactionResult setBalance(Currency currency, BigDecimal amount, Set<Context> contexts)
-
setBalance
TransactionResult setBalance(Currency currency, BigDecimal amount, Cause cause)
-
setBalance
default TransactionResult setBalance(Currency currency, BigDecimal amount)
-
resetBalances
Map<Currency,TransactionResult> resetBalances(Set<Context> contexts)
Resets the balances for allCurrencys used on this account to their default values (defaultBalance(Currency)), using the specifiedContexts.- Parameters:
contexts- theContexts to use when resetting the balances.- Returns:
- A map of
CurrencytoTransactionResult. Each entry represents the result of resetting a particular currency.
-
resetBalances
Map<Currency,TransactionResult> resetBalances(Cause cause)
Resets the balances for allCurrencys used on this account to their default values (defaultBalance(Currency)), using the specifiedCauses.- Parameters:
cause- the cause to computer context to use when resetting the balances.- Returns:
- A map of
CurrencytoTransactionResult. Each entry represents the result of resetting a particular currency.
-
resetBalances
default Map<Currency,TransactionResult> resetBalances()
Resets the balances for allCurrencys used on this account to their default values (defaultBalance(Currency)), using the current activeContext.- Returns:
- A map of
CurrencytoTransactionResult. Each entry represents the result of resetting a particular currency
-
resetBalance
TransactionResult resetBalance(Currency currency, Set<Context> contexts)
Resets the balance for the specifiedCurrencyto its default value (defaultBalance(Currency)), using the specifiedContexts.
-
resetBalance
TransactionResult resetBalance(Currency currency, Cause cause)
Resets the balance for the specifiedCurrencyto its default value (defaultBalance(Currency)), using context from the specifiedCause.- Parameters:
currency- TheCurrencyto reset the balance forcause- The cause to use to compute context when resetting the balance- Returns:
- The result of the transaction
-
resetBalance
default TransactionResult resetBalance(Currency currency)
Resets the balance for the specifiedCurrencyto its default value (defaultBalance(Currency)), using the current activeContexts.- Parameters:
currency- TheCurrencyto reset the balance for- Returns:
- The result of the transaction
-
deposit
TransactionResult deposit(Currency currency, BigDecimal amount, Set<Context> contexts)
-
deposit
TransactionResult deposit(Currency currency, BigDecimal amount, Cause cause)
-
deposit
default TransactionResult deposit(Currency currency, BigDecimal amount)
-
withdraw
TransactionResult withdraw(Currency currency, BigDecimal amount, Set<Context> contexts)
-
withdraw
TransactionResult withdraw(Currency currency, BigDecimal amount, Cause cause)
-
withdraw
default TransactionResult withdraw(Currency currency, BigDecimal amount)
-
transfer
TransferResult transfer(Account to, Currency currency, BigDecimal amount, Set<Context> contexts)
Transfers the specified amount of the specifiedCurrencyfrom this account the destination account, using the specifiedContexts.This operation is a merged
withdraw(Currency, BigDecimal, Cause)from this account with adeposit(Currency, BigDecimal, Cause)into the specified account.- Parameters:
to- the Account to transfer the amounts to.currency- TheCurrencyto transfer the specified amount foramount- The amount to transfer for the specifiedCurrencycontexts- TheContexts to use with the specifiedCurrencyand account- Returns:
- A
TransferResultrepresentative of the effects of the operation
-
transfer
TransferResult transfer(Account to, Currency currency, BigDecimal amount, Cause cause)
Transfers the specified amount of the specifiedCurrencyfrom this account the destination account, using the specifiedCause.This operation is a merged
withdraw(Currency, BigDecimal, Cause)from this account with adeposit(Currency, BigDecimal, Cause)into the specified account.- Parameters:
to- the Account to transfer the amounts to.currency- TheCurrencyto transfer the specified amount foramount- The amount to transfer for the specifiedCurrencycause- The cause to use with the specifiedCurrencyand account- Returns:
- A
TransferResultrepresentative of the effects of the operation
-
transfer
default TransferResult transfer(Account to, Currency currency, BigDecimal amount)
Transfers the specified amount of the specifiedCurrencyfrom this account the destination account, using the current activeContexts.This operation is a merged
withdraw(Currency, BigDecimal, Cause)from this account with adeposit(Currency, BigDecimal, Cause)into the specified account.- Parameters:
to- the Account to transfer the amounts to.currency- TheCurrencyto transfer the specified amount foramount- The amount to transfer for the specifiedCurrency- Returns:
- A
TransferResultrepresentative of the effects of the operation
-
-