diff --git a/Towny/pom.xml b/Towny/pom.xml index c933bf153f..bbd0dbadc0 100644 --- a/Towny/pom.xml +++ b/Towny/pom.xml @@ -141,7 +141,7 @@ net.milkbowl.vault VaultUnlockedAPI - 2.7 + 2.9 provided diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/EconomyAccount.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/EconomyAccount.java index 9cef22f4d7..cdcb815926 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/EconomyAccount.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/EconomyAccount.java @@ -18,7 +18,7 @@ */ public class EconomyAccount extends Account { protected EconomyAccount(Resident resident, String name, UUID uuid, Supplier worldSupplier) { - super(resident, name, uuid, worldSupplier); + super(resident, name, uuid, worldSupplier, true); } @Override diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/Account.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/Account.java index b416b3bd0e..1873ae0098 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/Account.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/Account.java @@ -53,14 +53,42 @@ public abstract class Account implements Nameable, Identifiable { private String name; private UUID uuid; private final Supplier worldSupplier; + private boolean playerAccount; private OfflinePlayer cachedOfflinePlayer; + + public Account(final EconomyHandler owner, final @NotNull String name, final @NotNull UUID uuid, final @Nullable Supplier worldSupplier, boolean playerAccount) { + this.economyHandler = owner; + this.name = name; + this.uuid = uuid; + this.worldSupplier = worldSupplier; + this.playerAccount = playerAccount; + + // ALL account transactions will route auditing data through this + // central auditor. + observers.add(GLOBAL_OBSERVER); + + try { + this.cachedBalance = new CachedBalance(getHoldingBalance(false)); + } catch (Exception e) { + Towny.getPlugin().getLogger().log(Level.WARNING, String.format("An exception occurred when initializing cached balance for an account (name: %s), see the below error for more details.", name), e); + } + } + + /** + * @deprecated since 0.101.0.6 use {@link #Account(EconomyHandler, String, UUID, Supplier, boolean)} instead. + * @param economyHandler economyHandler that owns this account. + * @param name name of the account owner. + * @param world world in which the account would exist. + */ + @Deprecated public Account(final EconomyHandler owner, final @NotNull String name, final @NotNull UUID uuid, final @Nullable Supplier worldSupplier) { this.economyHandler = owner; this.name = name; this.uuid = uuid; this.worldSupplier = worldSupplier; + this.playerAccount = false; // ALL account transactions will route auditing data through this // central auditor. @@ -74,7 +102,7 @@ public Account(final EconomyHandler owner, final @NotNull String name, final @No } /** - * @deprecated since 0.100.4.6 use {@link #Account(EconomyHandler, String, UUID, Supplier)} instead. + * @deprecated since 0.100.4.6 use {@link #Account(EconomyHandler, String, UUID, Supplier, boolean)} instead. * @param economyHandler economyHandler that owns this account. * @param name name of the account owner. * @param world world in which the account would exist. @@ -84,13 +112,14 @@ public Account(EconomyHandler economyHandler, String name, World world) { this.name = name; this.uuid = economyHandler instanceof Identifiable identifiable ? identifiable.getUUID() : null; this.economyHandler = economyHandler; + this.playerAccount = false; TownyWorld townyWorld = TownyAPI.getInstance().getTownyWorld(world); this.worldSupplier = () -> townyWorld; } /** - * @deprecated since 0.100.4.6 use {@link #Account(EconomyHandler, String, UUID, Supplier)} instead. + * @deprecated since 0.100.4.6 use {@link #Account(EconomyHandler, String, UUID, Supplier, boolean)} instead. * @param economyHandler economyHandler that owns this account. * @param name name of the account owner. */ @@ -100,6 +129,7 @@ public Account(EconomyHandler economyHandler, String name) { this.uuid = economyHandler instanceof Identifiable identifiable ? identifiable.getUUID() : null; this.economyHandler = economyHandler; this.worldSupplier = () -> TownyUniverse.getInstance().getTownyWorlds().get(0); + this.playerAccount = false; } // Template methods @@ -317,6 +347,14 @@ public void setUUID(final @NotNull UUID uuid) { this.cachedOfflinePlayer = null; } + public boolean isPlayerAccount() { + return playerAccount; + } + + public void setPlayerAccount(boolean playerAccount) { + this.playerAccount = playerAccount; + } + /** * Gets the observers of this account. * diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/BankAccount.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/BankAccount.java index 7dfd78addb..4fedaa9b13 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/BankAccount.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/BankAccount.java @@ -31,7 +31,7 @@ public class BankAccount extends Account { * @param government Town or Nation that is getting a BankAccount. */ public BankAccount(String name, Government government) { - super(government, name, TownyEconomyHandler.modifyNPCUUID(government.getUUID()), () -> TownyAPI.getInstance().getTownyWorld(government.getWorld())); + super(government, name, TownyEconomyHandler.modifyNPCUUID(government.getUUID()), () -> TownyAPI.getInstance().getTownyWorld(government.getWorld()), false); this.government = government; } diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/TownyServerAccount.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/TownyServerAccount.java index 751c09aa9a..2f6a378dde 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/TownyServerAccount.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/TownyServerAccount.java @@ -24,7 +24,7 @@ public final class TownyServerAccount extends Account { public static final TownyServerAccount ACCOUNT = new TownyServerAccount(); private TownyServerAccount() { - super(new EconomyHandlerHolder(), name, uuid, worldLocal::get); + super(new EconomyHandlerHolder(), name, uuid, worldLocal::get, false); } @Override diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/VaultUnlockedEconomyAdapter.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/VaultUnlockedEconomyAdapter.java index c2f76f5d29..6bfc23d34f 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/VaultUnlockedEconomyAdapter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/VaultUnlockedEconomyAdapter.java @@ -39,12 +39,12 @@ public boolean hasAccount(Account account) { @Override public double getBalance(Account account) { - return economy.getBalance(TOWNY, account.getUUID(), account.getWorld().getName()).doubleValue(); + return economy.balance(TOWNY, account.getUUID(), account.getWorld().getName()).doubleValue(); } @Override public void newAccount(Account account) { - economy.createAccount(account.getUUID(), account.getName(), account.getWorld().getName()); + economy.createAccount(account.getUUID(), account.getName(), account.getWorld().getName(), account.isPlayerAccount()); } @Override