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

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

  • 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

      @Deprecated @Nullable public @Nullable org.bukkit.World getBukkitWorld()
      Deprecated.
      since 0.100.4.6 use getWorld() instead.
      Fetch the current world for this object
      Returns:
      Bukkit world for the object
    • getWorld

      @NotNull public @NotNull TownyWorld getWorld()
    • 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.
    • getEconomyHandler

      public EconomyHandler getEconomyHandler()
      Returns:
      the EconomyHandler that this Account represents. Could be a Resident, Town, Nation or the TownyServerAccount.
    • 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)
    • getUUID

      @NotNull public @NotNull UUID getUUID()
      apiNote The returned uuid's version may differ from the object this represents in the case of NPC accounts.
      Specified by:
      getUUID in interface Identifiable
    • setUUID

      public void setUUID(@NotNull @NotNull UUID uuid)
      Description copied from interface: Identifiable
      This should only be used by internal loading methods!
      Specified by:
      setUUID in interface Identifiable
      Parameters:
      uuid - the UUID to set.
    • getObservers

      public @Unmodifiable 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.
    • asOfflinePlayer

      @Internal @NotNull public @NotNull org.bukkit.OfflinePlayer asOfflinePlayer()