Fix Vault No Economy Plugin Found Error (#613)

This commit is contained in:
Sascha Bartl 2024-12-17 21:00:03 +01:00 committed by GitHub
parent 1e40caa64a
commit c5fc9f76fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import com.Acrobot.ChestShop.Listeners.Block.BlockPlace;
import com.Acrobot.ChestShop.Listeners.Block.Break.ChestBreak;
import com.Acrobot.ChestShop.Listeners.Block.Break.SignBreak;
import com.Acrobot.ChestShop.Listeners.Block.SignCreate;
import com.Acrobot.ChestShop.Listeners.Economy.EconomyAdapter;
import com.Acrobot.ChestShop.Listeners.Economy.ServerAccountCorrector;
import com.Acrobot.ChestShop.Listeners.Economy.TaxModule;
import com.Acrobot.ChestShop.Listeners.AuthMeChestShopListener;
@ -92,6 +93,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@ -335,7 +337,7 @@ public class ChestShop extends JavaPlugin {
registerEvent(new com.Acrobot.ChestShop.Plugins.ChestShop()); //Chest protection
registerEvent(new Dependencies());
registerEvent(new NameManager());
registerPreShopCreationEvents();
@ -536,6 +538,16 @@ public class ChestShop extends JavaPlugin {
return new DrilldownPie(statId, () -> map);
}
public static DrilldownPie createStaticDrilldownStat(String statId, Callable<EconomyAdapter.ProviderInfo> callableProviderInfo) {
return new DrilldownPie(statId, () -> {
EconomyAdapter.ProviderInfo providerInfo = callableProviderInfo.call();
if (providerInfo == null) {
return ImmutableMap.of();
}
return ImmutableMap.of(providerInfo.getName(), ImmutableMap.of(providerInfo.getVersion(), 1));
});
}
private int[] getChartArray(boolean value) {
return new int[]{!value ? 1 : 0, value ? 0 : 1};
}

View File

@ -111,7 +111,7 @@ public class Dependencies implements Listener {
}
ChestShop.getMetrics().addCustomChart(ChestShop.createStaticDrilldownStat("economyAdapter", plugin, Bukkit.getPluginManager().getPlugin(plugin).getDescription().getVersion()));
ChestShop.getMetrics().addCustomChart(ChestShop.createStaticDrilldownStat("economyPlugin", economy.getProviderInfo().getName(), economy.getProviderInfo().getVersion()));
ChestShop.getMetrics().addCustomChart(ChestShop.createStaticDrilldownStat("economyPlugin", economy::getProviderInfo));
ChestShop.registerListener(economy);
ChestShop.getBukkitLogger().info(plugin + " loaded!");
@ -256,7 +256,7 @@ public class Dependencies implements Listener {
this.author = author;
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEnable(PluginEnableEvent event) {
Plugin plugin = event.getPlugin();

View File

@ -11,11 +11,13 @@ import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
import com.Acrobot.ChestShop.Events.Economy.CurrencyTransferEvent;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
import java.math.BigDecimal;
public abstract class EconomyAdapter implements Listener {
@Nullable
public abstract ProviderInfo getProviderInfo();
public abstract void onAmountCheck(CurrencyAmountEvent event);

View File

@ -33,7 +33,10 @@ public class ReserveListener extends EconomyAdapter {
}
@Override
public ProviderInfo getProviderInfo() {
public @Nullable ProviderInfo getProviderInfo() {
if (economyAPI == null) {
return null;
}
return new ProviderInfo(economyAPI.name(), economyAPI.version());
}

View File

@ -15,6 +15,7 @@ import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.event.server.ServiceRegisterEvent;
import org.bukkit.event.server.ServiceUnregisterEvent;
import org.bukkit.plugin.Plugin;
@ -64,7 +65,10 @@ public class VaultListener extends EconomyAdapter {
}
@Override
public ProviderInfo getProviderInfo() {
public @Nullable ProviderInfo getProviderInfo() {
if (provider == null) {
return null;
}
return new ProviderInfo(provider.getName(), providingPlugin.getDescription().getVersion());
}
@ -107,6 +111,17 @@ public class VaultListener extends EconomyAdapter {
}
}
@EventHandler
public void onServerLoad(ServerLoadEvent event) {
if (event.getType() == ServerLoadEvent.LoadType.STARTUP) {
// Server and plugins are loaded, so we can check for the economy provider now
if (provider == null) {
ChestShop.getBukkitLogger().log(Level.SEVERE, "No Vault compatible Economy plugin found!");
ChestShop.getBukkitServer().getPluginManager().disablePlugin(ChestShop.getPlugin());
}
}
}
@EventHandler
public void onAmountCheck(CurrencyAmountEvent event) {
if (!checkSetup() || event.wasHandled() || !event.getAmount().equals(BigDecimal.ZERO)) {