java.lang.Object
com.palmergames.bukkit.towny.object.economy.Account
All Implemented Interfaces:
Nameable
Direct Known Subclasses:
BankAccount, EconomyAccount, TownyServerAccount

public abstract class Account extends Object implements Nameable
Used to facilitate transactions regarding money, and the storage of funds.
Author:
Suneet Tipirneni (Siris)
See Also:
  • Field Details

    • cachedBalance

      protected com.palmergames.bukkit.towny.object.economy.Account.CachedBalance cachedBalance
  • Constructor Details

    • Account

      public Account(String name)
    • Account

      public Account(String name, org.bukkit.World world)
  • Method Details

    • addMoney

      protected abstract boolean addMoney(double amount)
    • subtractMoney

      protected abstract boolean subtractMoney(double amount)
    • deposit

      public boolean deposit(double amount, String reason)
      Attempts to add money to the account, and notifies account observers of any changes.
      Parameters:
      amount - The amount to add.
      reason - The reason for adding.
      Returns:
      boolean indicating success.
    • withdraw

      public boolean withdraw(double amount, String reason)
      Attempts to withdraw money from the account, and notifies account observers of any changes.
      Parameters:
      amount - The amount to withdraw.
      reason - The reason for subtracting.
      Returns:
      boolean indicating success.
    • payTo

      public boolean payTo(double amount, EconomyHandler collector, String reason)
      Pays another account the specified funds.
      Parameters:
      amount - The amount to pay.
      collector - The account to pay.
      reason - The reason for the pay.
      Returns:
      boolean indicating success.
    • payToServer

      protected boolean payToServer(double amount, String reason)
    • payFromServer

      protected boolean payFromServer(double amount, String reason)
    • payTo

      public boolean payTo(double amount, Account collector, String reason)
      Pays another account the specified funds.
      Parameters:
      amount - The amount to pay.
      collector - The account to pay.
      reason - The reason for the pay.
      Returns:
      boolean indicating success.
    • getBukkitWorld

      public org.bukkit.World getBukkitWorld()
      Fetch the current world for this object
      Returns:
      Bukkit world for the object
    • setBalance

      public boolean setBalance(double amount, String reason)
      Set balance and log this action
      Parameters:
      amount - currency to transact
      reason - memo regarding transaction
      Returns:
      true, or pay/collect balance for given reason
    • getHoldingBalance

      public double getHoldingBalance()
    • getHoldingBalance

      public double getHoldingBalance(boolean setCache)
      Gets the current balance of this account.
      Parameters:
      setCache - when True the account will have its cachedbalance set.
      Returns:
      The amount in this account.
    • canPayFromHoldings

      public boolean canPayFromHoldings(double amount)
      Does this object have enough in it's economy account to pay?
      Parameters:
      amount - currency to check for
      Returns:
      true if there is enough.
    • getHoldingFormattedBalance

      public String getHoldingFormattedBalance()
      Used To Get Balance of Players holdings in String format for printing
      Returns:
      current account balance formatted in a string.
    • removeAccount

      public void removeAccount()
      Attempt to delete the economy account.
    • getName

      public String getName()
      Description copied from interface: Nameable
      Get the name of the specified object
      Specified by:
      getName in interface Nameable
      Returns:
      A String representing the name of the object.
    • setName

      public void setName(String name)
    • getObservers

      public List<AccountObserver> getObservers()
      Gets the observers of this account.
      Returns:
      A list of account observers.
    • addObserver

      public final void addObserver(AccountObserver observer)
      Adds an account observer that listens to account changes.
      Parameters:
      observer - The observer to add.
    • removeObserver

      public final void removeObserver(AccountObserver observer)
      Removes an account observer that listens to account changes.
      Parameters:
      observer - The observer to remove.
    • getAuditor

      public final AccountAuditor getAuditor()
      Gets the auditor that audits this account.
      Returns:
      The auditor tracking this account.
    • setAuditor

      public final void setAuditor(AccountAuditor auditor)
      Sets the auditor that audits this account, and adds it as an observer.
      Parameters:
      auditor - The auditor to track this account.
    • getCachedBalance

      public double getCachedBalance()
      Returns a cached balance of an Account, the value of which can be brand new or up to 10 minutes old (time configurable in the config,) based on whether the cache has been checked recently.
      Returns:
      balance Double which is from a Account.CachedBalance.balance.
    • getCachedBalance

      public double getCachedBalance(boolean refreshIfStale)
      Returns a cached balance of an Account, the value of which can be brand new or up to 10 minutes old (time configurable in the config,) based on whether the cache has been checked recently.
      Parameters:
      refreshIfStale - when true, if the cache is stale it will update.
      Returns:
      balance Double which is from a Account.CachedBalance.balance.