Class Account
java.lang.Object
com.palmergames.bukkit.towny.object.economy.Account
- All Implemented Interfaces:
Identifiable
,Nameable
- Direct Known Subclasses:
BankAccount
,EconomyAccount
,TownyServerAccount
Used to facilitate transactions regarding money,
and the storage of funds.
- Author:
- Suneet Tipirneni (Siris)
- See Also:
-
Constructor Summary
ConstructorDescriptionAccount
(EconomyHandler owner, @NotNull String name, @NotNull UUID uuid, @Nullable Supplier<TownyWorld> worldSupplier) Account
(EconomyHandler economyHandler, String name) Deprecated.Account
(EconomyHandler economyHandler, String name, org.bukkit.World world) Deprecated.since 0.100.4.6 useAccount(EconomyHandler, String, UUID, Supplier)
instead. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
addMoney
(double amount) final void
addObserver
(AccountObserver observer) Adds an account observer that listens to account changes.@NotNull org.bukkit.OfflinePlayer
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.@Nullable org.bukkit.World
Deprecated.since 0.100.4.6 usegetWorld()
instead.double
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 object@Unmodifiable List
<AccountObserver> Gets the observers of this account.@NotNull UUID
getUUID()
apiNote The returned uuid's version may differ from the object this represents in the case of NPC accounts.@NotNull TownyWorld
getWorld()
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
void
This should only be used by internal loading methods!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
-
Constructor Details
-
Account
public Account(EconomyHandler owner, @NotNull @NotNull String name, @NotNull @NotNull UUID uuid, @Nullable @Nullable Supplier<TownyWorld> worldSupplier) -
Account
Deprecated.since 0.100.4.6 useAccount(EconomyHandler, String, UUID, Supplier)
instead.- Parameters:
economyHandler
- economyHandler that owns this account.name
- name of the account owner.world
- world in which the account would exist.
-
Account
Deprecated.since 0.100.4.6 useAccount(EconomyHandler, String, UUID, Supplier)
instead.- Parameters:
economyHandler
- economyHandler that owns this account.name
- name of the account owner.
-
-
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
Deprecated.since 0.100.4.6 usegetWorld()
instead.Fetch the current world for this object- Returns:
- Bukkit world for the object
-
getWorld
-
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. -
getEconomyHandler
- Returns:
- the EconomyHandler that this Account represents. Could be a Resident, Town, Nation or the TownyServerAccount.
-
getName
Description copied from interface:Nameable
Get the name of the specified object -
setName
-
getUUID
apiNote The returned uuid's version may differ from the object this represents in the case of NPC accounts.- Specified by:
getUUID
in interfaceIdentifiable
-
setUUID
Description copied from interface:Identifiable
This should only be used by internal loading methods!- Specified by:
setUUID
in interfaceIdentifiable
- Parameters:
uuid
- the UUID to set.
-
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
.
-
asOfflinePlayer
@Internal @NotNull public @NotNull org.bukkit.OfflinePlayer asOfflinePlayer()
-
Account(EconomyHandler, String, UUID, Supplier)
instead.