Interface Account

  • All Superinterfaces:
    Contextual
    All Known Subinterfaces:
    UniqueAccount, VirtualAccount

    public interface Account
    extends Contextual
    Represents an account, which stores amounts of various currencies.

    Accounts come in two varieties: user accounts and VirtualAccount virtual accounts. Unique accounts are bound to a UUID, usually of a particular User's GameProfile. Virtual accounts are identified by a String identifier, which may have any value. They are not tied to any Entity, player or otherwise. Virtual accounts may be used for purposes such as bank accounts, non-player Entity accounts, or other things.

    • 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 or VirtualAccount).

        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 specified Currency.

        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 the Contexts 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 specified Currency, with the specified Contexts.

        If this method returns false, then defaultBalance(Currency) will be used when retrieving a balance for the specified Currency with the specified Contexts.

        Parameters:
        currency - The Currency to determine if a balance is set for
        contexts - The Contexts to use with the Currency
        Returns:
        Whether this account has a set balance for the specified Currency and Contexts
      • hasBalance

        boolean hasBalance​(Currency currency,
                           Cause cause)
        Returns whether this account has a set balance for the specified Currency, with context from the specified Causes.

        If this method returns false, then defaultBalance(Currency) will be used when retrieving a balance for the specified Currency with the specified Contexts.

        Parameters:
        currency - The Currency to determine if a balance is set for
        cause - The Cause to use to compute context for this Currency
        Returns:
        Whether this account has a set balance for the specified Currency and Contexts
      • hasBalance

        default boolean hasBalance​(Currency currency)
        Returns whether this account has a set balance for the specified Currency, with the current active cause.

        If this method returns false, then defaultBalance(Currency) will be used when retrieving a balance for the specifid Currency with the current active cause

        .
        Parameters:
        currency - The Currency to determine if a balance is set for.
        Returns:
        Whether this account has a set balance for the specified Currency and current active cause.
      • balance

        java.math.BigDecimal balance​(Currency currency,
                                     java.util.Set<Context> contexts)
        Returns a BigDecimal representative of the balance stored within this Account for the Currency given and the set of Contexts.

        The default result when the account does not have a balance of the given Currency will be defaultBalance(Currency).

        The balance may be unavailable depending on the set of Contexts used.

        Parameters:
        currency - a Currency to check the balance of
        contexts - a set of Contexts to check the balance against
        Returns:
        The value for the specified Currency with the specified Contexts.
      • balance

        java.math.BigDecimal balance​(Currency currency,
                                     Cause cause)
        Returns a BigDecimal representative of the balance stored within this Account for the Currency given and the set of Contexts.

        The default result when the account does not have a balance of the given Currency will be defaultBalance(Currency).

        The balance may be unavailable depending on the set of Contexts used.

        Parameters:
        currency - a Currency to check the balance of
        cause - a cause used for deriving context to check the balance against
        Returns:
        The value for the specified Currency with the specified Cause.
      • balance

        default java.math.BigDecimal balance​(Currency currency)
        Returns a BigDecimal representative of the balance stored within this Account for the Currency given, with the current active cause.

        The default result when the account does not have a balance of the given Currency will be defaultBalance(Currency).

        Parameters:
        currency - a Currency to check the balance of
        Returns:
        the value for the specified Currency.
      • balances

        java.util.Map<Currency,​java.math.BigDecimal> balances​(java.util.Set<Context> contexts)
        Returns a Map of all currently set balances the account holds within the set of Contexts.

        Amounts may differ depending on the Contexts specified and the implementation. The set of Contexts 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 underlying Account. See setBalance(Currency, BigDecimal, Cause) to set values.

        Parameters:
        contexts - the set of Contexts to use with the specified amounts
        Returns:
        A Map of Currency to BigDecimal amounts that this account holds
      • balances

        java.util.Map<Currency,​java.math.BigDecimal> balances​(Cause cause)
        Returns a Map of all currently set balances the account holds within the set of Contexts.

        Amounts may differ depending on the Cause specified and the implementation. The set of Contexts 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 underlying Account. See setBalance(Currency, BigDecimal, Cause) to set values.

        Parameters:
        cause - the set of Contexts to use with the specified amounts
        Returns:
        A Map of Currency to BigDecimal amounts that this account holds
      • balances

        default java.util.Map<Currency,​java.math.BigDecimal> balances()
        Returns a Map of all currently set balances the account holds within the current active Context.

        Amounts may differ depending on the Contexts specified and the implementation. The set of Contexts 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 underlying Account and may result in runtime exceptions depending on implementation. See setBalance(Currency, BigDecimal, Cause) to set values.

        Returns:
        A Map of Currency to BigDecimal amounts that this account holds
      • setBalance

        TransactionResult setBalance​(Currency currency,
                                     java.math.BigDecimal amount,
                                     java.util.Set<Context> contexts)
        Sets the balance for this account to the specified amount for the specified Currency, with the specified set of Contexts.

        Negative balances may or may not be supported depending on the Currency specified and the implementation.

        Parameters:
        currency - The Currency to set the balance for
        amount - The amount to set for the specified Currency
        contexts - The set of Contexts to use with the specified Currency
        Returns:
        The result of the transaction
      • setBalance

        TransactionResult setBalance​(Currency currency,
                                     java.math.BigDecimal amount,
                                     Cause cause)
        Sets the balance for this account to the specified amount for the specified Currency, with the specified Cause.

        Negative balances may or may not be supported depending on the Currency specified and the implementation.

        Parameters:
        currency - The Currency to set the balance for
        amount - The amount to set for the specified Currency
        cause - The cause used to computer context to use with the specified Currency
        Returns:
        The result of the transaction
      • setBalance

        default TransactionResult setBalance​(Currency currency,
                                             java.math.BigDecimal amount)
        Sets the balance for this account to the specified amount for the specified Currency, with the current active Contexts.

        Negative balances may or may not be supported depending on the Currency specified and the implementation.

        Parameters:
        currency - The Currency to set the balance for
        amount - The amount to set for the specified Currency
        Returns:
        The result of the transaction
      • resetBalance

        TransactionResult resetBalance​(Currency currency,
                                       Cause cause)
        Resets the balance for the specified Currency to its default value (defaultBalance(Currency)), using context from the specified Cause.
        Parameters:
        currency - The Currency to reset the balance for
        cause - The cause to use to compute context when resetting the balance
        Returns:
        The result of the transaction
      • deposit

        TransactionResult deposit​(Currency currency,
                                  java.math.BigDecimal amount,
                                  java.util.Set<Context> contexts)
        Deposits the specified amount of the specified Currency to this account, using the specified Contexts.
        Parameters:
        currency - The Currency to deposit the specified amount for
        amount - The amount to deposit for the specified Currency
        contexts - the Contexts to use with the specified Currency
        Returns:
        The result of the transaction
      • deposit

        TransactionResult deposit​(Currency currency,
                                  java.math.BigDecimal amount,
                                  Cause cause)
        Deposits the specified amount of the specified Currency to this account, using the specified Cause.
        Parameters:
        currency - The Currency to deposit the specified amount for
        amount - The amount to deposit for the specified Currency
        cause - the cause to use to compute context with the specified Currency
        Returns:
        The result of the transaction
      • deposit

        default TransactionResult deposit​(Currency currency,
                                          java.math.BigDecimal amount)
        Deposits the given amount of the specified Currency to this account, using the current active Contexts.
        Parameters:
        currency - The Currency to deposit the specified amount for
        amount - The amount to deposit for the specified Currency
        Returns:
        The result of the transaction
      • withdraw

        TransactionResult withdraw​(Currency currency,
                                   java.math.BigDecimal amount,
                                   java.util.Set<Context> contexts)
        Withdraws the specified amount of the specified Currency from this account, using the specified Contexts.
        Parameters:
        currency - The Currency to deposit the specified amount for
        amount - The amount to deposit for the specified Currency
        contexts - The Contexts to use with the specified Currency
        Returns:
        The result of the transaction
      • withdraw

        TransactionResult withdraw​(Currency currency,
                                   java.math.BigDecimal amount,
                                   Cause cause)
        Withdraws the specified amount of the specified Currency from this account, using the specified Cause.
        Parameters:
        currency - The Currency to deposit the specified amount for
        amount - The amount to deposit for the specified Currency
        cause - The cause to use to compute context with the specified Currency
        Returns:
        The result of the transaction
      • withdraw

        default TransactionResult withdraw​(Currency currency,
                                           java.math.BigDecimal amount)
        Withdraws the specified amount of the specified Currency from this account, using the current active Contexts.
        Parameters:
        currency - The Currency to deposit the specified amount for
        amount - The amount to deposit for the specified Currency
        Returns:
        The result of the transaction