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 accounts
andVirtualAccount
virtual 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-playerEntity
accounts, or other things.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.math.BigDecimal
balance(Currency currency)
java.math.BigDecimal
balance(Currency currency, java.util.Set<Context> contexts)
java.math.BigDecimal
balance(Currency currency, Cause cause)
default java.util.Map<Currency,java.math.BigDecimal>
balances()
Returns aMap
of all currently set balances the account holds within the current activeContext
.java.util.Map<Currency,java.math.BigDecimal>
balances(java.util.Set<Context> contexts)
Returns aMap
of all currently set balances the account holds within the set ofContext
s.java.util.Map<Currency,java.math.BigDecimal>
balances(Cause cause)
Returns aMap
of all currently set balances the account holds within the set ofContext
s.java.math.BigDecimal
defaultBalance(Currency currency)
Gets the default balance of this account for the specifiedCurrency
.default TransactionResult
deposit(Currency currency, java.math.BigDecimal amount)
TransactionResult
deposit(Currency currency, java.math.BigDecimal amount, java.util.Set<Context> contexts)
TransactionResult
deposit(Currency currency, java.math.BigDecimal amount, Cause cause)
Component
displayName()
Gets the display name for this account.default boolean
hasBalance(Currency currency)
Returns whether this account has a set balance for the specifiedCurrency
, with the current active cause.boolean
hasBalance(Currency currency, java.util.Set<Context> contexts)
boolean
hasBalance(Currency currency, Cause cause)
default TransactionResult
resetBalance(Currency currency)
Resets the balance for the specifiedCurrency
to its default value (defaultBalance(Currency)
), using the current activeContext
s.TransactionResult
resetBalance(Currency currency, java.util.Set<Context> contexts)
Resets the balance for the specifiedCurrency
to its default value (defaultBalance(Currency)
), using the specifiedContext
s.TransactionResult
resetBalance(Currency currency, Cause cause)
Resets the balance for the specifiedCurrency
to its default value (defaultBalance(Currency)
), using context from the specifiedCause
.default java.util.Map<Currency,TransactionResult>
resetBalances()
Resets the balances for allCurrency
s used on this account to their default values (defaultBalance(Currency)
), using the current activeContext
.java.util.Map<Currency,TransactionResult>
resetBalances(java.util.Set<Context> contexts)
Resets the balances for allCurrency
s used on this account to their default values (defaultBalance(Currency)
), using the specifiedContext
s.java.util.Map<Currency,TransactionResult>
resetBalances(Cause cause)
Resets the balances for allCurrency
s used on this account to their default values (defaultBalance(Currency)
), using the specifiedCause
s.default TransactionResult
setBalance(Currency currency, java.math.BigDecimal amount)
TransactionResult
setBalance(Currency currency, java.math.BigDecimal amount, java.util.Set<Context> contexts)
TransactionResult
setBalance(Currency currency, java.math.BigDecimal amount, Cause cause)
default TransferResult
transfer(Account to, Currency currency, java.math.BigDecimal amount)
TransferResult
transfer(Account to, Currency currency, java.math.BigDecimal amount, java.util.Set<Context> contexts)
TransferResult
transfer(Account to, Currency currency, java.math.BigDecimal amount, Cause cause)
default TransactionResult
withdraw(Currency currency, java.math.BigDecimal amount)
TransactionResult
withdraw(Currency currency, java.math.BigDecimal amount, java.util.Set<Context> contexts)
TransactionResult
withdraw(Currency currency, java.math.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 (
UniqueAccount
orVirtualAccount
).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
java.math.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
Currency
on this account, or if no balance is available for theContext
s 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, java.util.Set<Context> contexts)
Returns whether this account has a set balance for the specifiedCurrency
, with the specifiedContext
s.If this method returns
false
, thendefaultBalance(Currency)
will be used when retrieving a balance for the specifiedCurrency
with the specifiedContext
s.
-
hasBalance
boolean hasBalance(Currency currency, Cause cause)
Returns whether this account has a set balance for the specifiedCurrency
, with context from the specifiedCause
s.If this method returns
false
, thendefaultBalance(Currency)
will be used when retrieving a balance for the specifiedCurrency
with the specifiedContext
s.
-
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 specifidCurrency
with the current active cause
-
balance
java.math.BigDecimal balance(Currency currency, java.util.Set<Context> contexts)
Returns aBigDecimal
representative of the balance stored within thisAccount
for theCurrency
given and the set ofContext
s.The default result when the account does not have a balance of the given
Currency
will bedefaultBalance(Currency)
.The balance may be unavailable depending on the set of
Context
s used.
-
balance
java.math.BigDecimal balance(Currency currency, Cause cause)
Returns aBigDecimal
representative of the balance stored within thisAccount
for theCurrency
given and the set ofContext
s.The default result when the account does not have a balance of the given
Currency
will bedefaultBalance(Currency)
.The balance may be unavailable depending on the set of
Context
s used.
-
balance
default java.math.BigDecimal balance(Currency currency)
Returns aBigDecimal
representative of the balance stored within thisAccount
for theCurrency
given, with the current active cause.The default result when the account does not have a balance of the given
Currency
will bedefaultBalance(Currency)
.
-
balances
java.util.Map<Currency,java.math.BigDecimal> balances(java.util.Set<Context> contexts)
Returns aMap
of all currently set balances the account holds within the set ofContext
s.Amounts may differ depending on the
Context
s specified and the implementation. The set ofContext
s may be empty.Currency
amounts which are 0 may or may not be included in the returned mapping.Changes to the returned
Map
will not be reflected in the underlyingAccount
. SeesetBalance(Currency, BigDecimal, Cause)
to set values.
-
balances
java.util.Map<Currency,java.math.BigDecimal> balances(Cause cause)
Returns aMap
of all currently set balances the account holds within the set ofContext
s.Amounts may differ depending on the
Cause
specified and the implementation. The set ofContext
s may be empty.Currency
amounts which are 0 may or may not be included in the returned mapping.Changes to the returned
Map
will not be reflected in the underlyingAccount
. SeesetBalance(Currency, BigDecimal, Cause)
to set values.
-
balances
default java.util.Map<Currency,java.math.BigDecimal> balances()
Returns aMap
of all currently set balances the account holds within the current activeContext
.Amounts may differ depending on the
Context
s specified and the implementation. The set ofContext
s may be empty.Currency
amounts which are 0 may or may not be included in the returned mapping.Changes to the returned
Map
will not be reflected in the underlyingAccount
and may result in runtime exceptions depending on implementation. SeesetBalance(Currency, BigDecimal, Cause)
to set values.- Returns:
- A
Map
ofCurrency
toBigDecimal
amounts that this account holds
-
setBalance
TransactionResult setBalance(Currency currency, java.math.BigDecimal amount, java.util.Set<Context> contexts)
-
setBalance
TransactionResult setBalance(Currency currency, java.math.BigDecimal amount, Cause cause)
-
setBalance
default TransactionResult setBalance(Currency currency, java.math.BigDecimal amount)
-
resetBalances
java.util.Map<Currency,TransactionResult> resetBalances(java.util.Set<Context> contexts)
Resets the balances for allCurrency
s used on this account to their default values (defaultBalance(Currency)
), using the specifiedContext
s.- Parameters:
contexts
- theContext
s to use when resetting the balances.- Returns:
- A map of
Currency
toTransactionResult
. Each entry represents the result of resetting a particular currency.
-
resetBalances
java.util.Map<Currency,TransactionResult> resetBalances(Cause cause)
Resets the balances for allCurrency
s used on this account to their default values (defaultBalance(Currency)
), using the specifiedCause
s.- Parameters:
cause
- the cause to computer context to use when resetting the balances.- Returns:
- A map of
Currency
toTransactionResult
. Each entry represents the result of resetting a particular currency.
-
resetBalances
default java.util.Map<Currency,TransactionResult> resetBalances()
Resets the balances for allCurrency
s used on this account to their default values (defaultBalance(Currency)
), using the current activeContext
.- Returns:
- A map of
Currency
toTransactionResult
. Each entry represents the result of resetting a particular currency
-
resetBalance
TransactionResult resetBalance(Currency currency, java.util.Set<Context> contexts)
Resets the balance for the specifiedCurrency
to its default value (defaultBalance(Currency)
), using the specifiedContext
s.
-
resetBalance
TransactionResult resetBalance(Currency currency, Cause cause)
Resets the balance for the specifiedCurrency
to its default value (defaultBalance(Currency)
), using context from the specifiedCause
.- Parameters:
currency
- TheCurrency
to 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 specifiedCurrency
to its default value (defaultBalance(Currency)
), using the current activeContext
s.- Parameters:
currency
- TheCurrency
to reset the balance for- Returns:
- The result of the transaction
-
deposit
TransactionResult deposit(Currency currency, java.math.BigDecimal amount, java.util.Set<Context> contexts)
-
deposit
TransactionResult deposit(Currency currency, java.math.BigDecimal amount, Cause cause)
-
deposit
default TransactionResult deposit(Currency currency, java.math.BigDecimal amount)
-
withdraw
TransactionResult withdraw(Currency currency, java.math.BigDecimal amount, java.util.Set<Context> contexts)
-
withdraw
TransactionResult withdraw(Currency currency, java.math.BigDecimal amount, Cause cause)
-
withdraw
default TransactionResult withdraw(Currency currency, java.math.BigDecimal amount)
-
transfer
TransferResult transfer(Account to, Currency currency, java.math.BigDecimal amount, java.util.Set<Context> contexts)
Transfers the specified amount of the specifiedCurrency
from this account the destination account, using the specifiedContext
s.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
- TheCurrency
to transfer the specified amount foramount
- The amount to transfer for the specifiedCurrency
contexts
- TheContext
s to use with the specifiedCurrency
and account- Returns:
- A
TransferResult
representative of the effects of the operation
-
transfer
TransferResult transfer(Account to, Currency currency, java.math.BigDecimal amount, Cause cause)
Transfers the specified amount of the specifiedCurrency
from 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
- TheCurrency
to transfer the specified amount foramount
- The amount to transfer for the specifiedCurrency
cause
- The cause to use with the specifiedCurrency
and account- Returns:
- A
TransferResult
representative of the effects of the operation
-
transfer
default TransferResult transfer(Account to, Currency currency, java.math.BigDecimal amount)
Transfers the specified amount of the specifiedCurrency
from this account the destination account, using the current activeContext
s.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
- TheCurrency
to transfer the specified amount foramount
- The amount to transfer for the specifiedCurrency
- Returns:
- A
TransferResult
representative of the effects of the operation
-
-