diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyEconomyHandler.java b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyEconomyHandler.java index f77b952a8e..b45a7fa2d8 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyEconomyHandler.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyEconomyHandler.java @@ -21,6 +21,7 @@ import net.tnemc.core.Reserve; import org.bukkit.World; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,6 +31,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.Executor; +import java.util.function.Function; /** * Economy handler to interface with Register or Vault directly. @@ -43,7 +45,7 @@ public class TownyEconomyHandler { private static EconomyAdapter economy = null; private static EconomyProvider provider = null; private static String version = ""; - + private static final Executor ECONOMY_EXECUTOR = runnable -> { if (TownySettings.isEconomyAsync() && plugin.getScheduler().isTickThread()) plugin.getScheduler().runAsync(runnable); @@ -137,9 +139,9 @@ public static String getVersion() { */ public static boolean setupEconomy() { - if (plugin.getServer().getPluginManager().isPluginEnabled("Vault")) + if (vaultUnlockedPresent()) provider = new VaultUnlockedEconomyProvider(); - else if (plugin.getServer().getPluginManager().isPluginEnabled("Vault")) + else if (vaultPresent()) provider = new VaultEconomyProvider(); else if (plugin.getServer().getPluginManager().isPluginEnabled("Reserve")) provider = new ReserveEconomyProvider((Reserve) plugin.getServer().getPluginManager().getPlugin("Reserve")); @@ -163,6 +165,18 @@ else if (plugin.getServer().getPluginManager().isPluginEnabled("Reserve")) return false; } + private static Function vaultVersionFun = (vault) -> vault.getDescription().getVersion().startsWith("1"); + + private static boolean vaultUnlockedPresent() { + Plugin vault = plugin.getServer().getPluginManager().getPlugin("Vault"); + return vault != null && vault.isEnabled() && !vaultVersionFun.apply(vault); + } + + private static boolean vaultPresent() { + Plugin vault = plugin.getServer().getPluginManager().getPlugin("Vault"); + return vault != null && vault.isEnabled() && vaultVersionFun.apply(vault); + } + /** * @deprecated since 0.100.4.6, use {@link #removeAccount(Account)} instead. * @param accountName legacy account name. diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/EconomyAdapter.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/EconomyAdapter.java index a13bebeac6..82156d28c8 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/EconomyAdapter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/EconomyAdapter.java @@ -65,7 +65,7 @@ public interface EconomyAdapter { * @param account the Account to rename. * @param newName the name to give the Account. */ - void renameAccount(Account account, String newName); + boolean renameAccount(Account account, String newName); /** * Sets the balance of the account. diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/ReserveEconomyAdapter.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/ReserveEconomyAdapter.java index c36eb239a6..05b74adf30 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/ReserveEconomyAdapter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/ReserveEconomyAdapter.java @@ -63,8 +63,9 @@ public String getFormattedBalance(double balance) { } @Override - public void renameAccount(Account account, String newName) { + public boolean renameAccount(Account account, String newName) { // Unused in Reserve. + return true; } public static class Legacy extends ReserveEconomyAdapter { diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/VaultEconomyAdapter.java b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/VaultEconomyAdapter.java index ac4ac1cc28..d5f954d819 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/VaultEconomyAdapter.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/object/economy/adapter/VaultEconomyAdapter.java @@ -73,8 +73,9 @@ public String getFormattedBalance(double balance) { } @Override - public void renameAccount(Account account, String newName) { + public boolean renameAccount(Account account, String newName) { // Unused in Vault. + return true; } @SuppressWarnings("deprecation") 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 d9e62afbae..c2f76f5d29 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 @@ -53,8 +53,8 @@ public void deleteAccount(Account account) { } @Override - public void renameAccount(Account account, String newName) { - economy.renameAccount(TOWNY, account.getUUID(), newName); + public boolean renameAccount(Account account, String newName) { + return economy.renameAccount(TOWNY, account.getUUID(), newName); } @Override