Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update VaultUnlocked support 2.9.0. #7715

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading