Skip to content

Commit

Permalink
Change renameAccount to a boolean, change the
Browse files Browse the repository at this point in the history
vault/vaultunlocked-finding methods to something that will actually
work.
  • Loading branch information
LlmDl committed Oct 26, 2024
1 parent 18b166b commit 165cee2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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"));
Expand All @@ -163,6 +165,18 @@ else if (plugin.getServer().getPluginManager().isPluginEnabled("Reserve"))
return false;
}

private static Function<Plugin, Boolean> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 165cee2

Please sign in to comment.