Skip to content

Commit

Permalink
Update VaultUnlocked support 2.9.0. (#7715)
Browse files Browse the repository at this point in the history
  • Loading branch information
LlmDl authored Jan 6, 2025
1 parent 659ac50 commit 60b038a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultUnlockedAPI</artifactId>
<version>2.7</version>
<version>2.9</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class EconomyAccount extends Account {
protected EconomyAccount(Resident resident, String name, UUID uuid, Supplier<TownyWorld> worldSupplier) {
super(resident, name, uuid, worldSupplier);
super(resident, name, uuid, worldSupplier, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,42 @@ public abstract class Account implements Nameable, Identifiable {
private String name;
private UUID uuid;
private final Supplier<TownyWorld> worldSupplier;
private boolean playerAccount;

private OfflinePlayer cachedOfflinePlayer;


public Account(final EconomyHandler owner, final @NotNull String name, final @NotNull UUID uuid, final @Nullable Supplier<TownyWorld> 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<TownyWorld> 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.
Expand All @@ -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.
Expand All @@ -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.
*/
Expand All @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 60b038a

Please sign in to comment.