Class Account
java.lang.Object
com.palmergames.bukkit.towny.object.economy.Account
- All Implemented Interfaces:
Nameable
- Direct Known Subclasses:
BankAccount
,EconomyAccount
,TownyServerAccount
Used to facilitate transactions regarding money,
and the storage of funds.
- Author:
- Suneet Tipirneni (Siris)
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected com.palmergames.bukkit.towny.object.economy.Account.CachedBalance
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
addMoney
(double amount) final void
addObserver
(AccountObserver observer) Adds an account observer that listens to account changes.boolean
canPayFromHoldings
(double amount) Does this object have enough in it's economy account to pay?boolean
Attempts to add money to the account, and notifies account observers of any changes.final AccountAuditor
Gets the auditor that audits this account.org.bukkit.World
Fetch the current world for this objectdouble
Returns a cached balance of anAccount
, 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.double
getCachedBalance
(boolean refreshIfStale) Returns a cached balance of anAccount
, 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.double
double
getHoldingBalance
(boolean setCache) Gets the current balance of this account.Used To Get Balance of Players holdings in String format for printinggetName()
Get the name of the specified objectGets the observers of this account.protected boolean
payFromServer
(double amount, String reason) boolean
Pays another account the specified funds.boolean
payTo
(double amount, EconomyHandler collector, String reason) Pays another account the specified funds.protected boolean
payToServer
(double amount, String reason) void
Attempt to delete the economy account.final void
removeObserver
(AccountObserver observer) Removes an account observer that listens to account changes.final void
setAuditor
(AccountAuditor auditor) Sets the auditor that audits this account, and adds it as an observer.boolean
setBalance
(double amount, String reason) Set balance and log this actionvoid
protected abstract boolean
subtractMoney
(double amount) boolean
Attempts to withdraw money from the account, and notifies account observers of any changes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.palmergames.bukkit.towny.object.Nameable
getFormattedName
-
Field Details
-
cachedBalance
protected com.palmergames.bukkit.towny.object.economy.Account.CachedBalance cachedBalance
-
-
Constructor Details
-
Account
-
Account
-
-
Method Details
-
addMoney
protected abstract boolean addMoney(double amount) -
subtractMoney
protected abstract boolean subtractMoney(double amount) -
deposit
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
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
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
-
payFromServer
-
payTo
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
Set balance and log this action- Parameters:
amount
- currency to transactreason
- 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
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
Description copied from interface:Nameable
Get the name of the specified object -
setName
-
getObservers
Gets the observers of this account.- Returns:
- A list of account observers.
-
addObserver
Adds an account observer that listens to account changes.- Parameters:
observer
- The observer to add.
-
removeObserver
Removes an account observer that listens to account changes.- Parameters:
observer
- The observer to remove.
-
getAuditor
Gets the auditor that audits this account.- Returns:
- The auditor tracking this account.
-
setAuditor
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 anAccount
, 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 aAccount.CachedBalance.balance
.
-
getCachedBalance
public double getCachedBalance(boolean refreshIfStale) Returns a cached balance of anAccount
, 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 aAccount.CachedBalance.balance
.
-