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
ConstructorsConstructorDescriptionAccount(EconomyHandler owner, @NotNull String name, @NotNull UUID uuid, @Nullable Supplier<TownyWorld> worldSupplier) Deprecated.Account(EconomyHandler owner, @NotNull String name, @NotNull UUID uuid, @Nullable Supplier<TownyWorld> worldSupplier, boolean playerAccount) Account(EconomyHandler economyHandler, String name) Deprecated.since 0.100.4.6 useAccount(EconomyHandler, String, UUID, Supplier, boolean)instead.Account(EconomyHandler economyHandler, String name, org.bukkit.World world) Deprecated.since 0.100.4.6 useAccount(EconomyHandler, String, UUID, Supplier, boolean)instead. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanaddMoney(double amount) final voidaddObserver(AccountObserver observer) Adds an account observer that listens to account changes.@NotNull org.bukkit.OfflinePlayerbooleancanPayFromHoldings(double amount) Does this object have enough in it's economy account to pay?booleanAttempts to add money to the account, and notifies account observers of any changes.final AccountAuditorGets the auditor that audits this account.@Nullable org.bukkit.WorldDeprecated.since 0.100.4.6 usegetWorld()instead.doubleReturns 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.doublegetCachedBalance(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.doubledoublegetHoldingBalance(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 UUIDgetUUID()apiNote The returned uuid's version may differ from the object this represents in the case of NPC accounts.@NotNull TownyWorldgetWorld()booleanprotected booleanpayFromServer(double amount, String reason) booleanPays another account the specified funds.booleanpayTo(double amount, EconomyHandler collector, String reason) Pays another account the specified funds.protected booleanpayToServer(double amount, String reason) voidAttempt to delete the economy account.final voidremoveObserver(AccountObserver observer) Removes an account observer that listens to account changes.final voidsetAuditor(AccountAuditor auditor) Sets the auditor that audits this account, and adds it as an observer.booleansetBalance(double amount, String reason) Set balance and log this actionvoidvoidsetPlayerAccount(boolean playerAccount) voidThis should only be used by internal loading methods!protected abstract booleansubtractMoney(double amount) booleanAttempts 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, waitMethods 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, boolean playerAccount) -
Account
@Deprecated public Account(EconomyHandler owner, @NotNull @NotNull String name, @NotNull @NotNull UUID uuid, @Nullable @Nullable Supplier<TownyWorld> worldSupplier) Deprecated.since 0.101.0.6 useAccount(EconomyHandler, String, UUID, Supplier, boolean)instead.- Parameters:
owner- economyHandler that owns this account.name- name of the account owner.uuid- UUID of the account owner.worldSupplier- world in which the account would exist.
-
Account
Deprecated.since 0.100.4.6 useAccount(EconomyHandler, String, UUID, Supplier, boolean)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, boolean)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:NameableGet 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:
getUUIDin interfaceIdentifiable
-
setUUID
Description copied from interface:IdentifiableThis should only be used by internal loading methods!- Specified by:
setUUIDin interfaceIdentifiable- Parameters:
uuid- the UUID to set.
-
isPlayerAccount
public boolean isPlayerAccount() -
setPlayerAccount
public void setPlayerAccount(boolean playerAccount) -
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
Doublewhich 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
Doublewhich is from aAccount.CachedBalance.balance.
-
asOfflinePlayer
@Internal @NotNull public @NotNull org.bukkit.OfflinePlayer asOfflinePlayer()
-
Account(EconomyHandler, String, UUID, Supplier, boolean)instead.