diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index 5f968146d..72a4f89e3 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -14,6 +14,7 @@ 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.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 @@ private void registerEvents() { registerEvent(new com.Acrobot.ChestShop.Plugins.ChestShop()); //Chest protection registerEvent(new Dependencies()); - + registerEvent(new NameManager()); registerPreShopCreationEvents(); @@ -536,6 +538,16 @@ public static DrilldownPie createStaticDrilldownStat(String statId, String value return new DrilldownPie(statId, () -> map); } + public static DrilldownPie createStaticDrilldownStat(String statId, Callable 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}; } diff --git a/src/main/java/com/Acrobot/ChestShop/Dependencies.java b/src/main/java/com/Acrobot/ChestShop/Dependencies.java index aae481e3c..2baab2d2d 100644 --- a/src/main/java/com/Acrobot/ChestShop/Dependencies.java +++ b/src/main/java/com/Acrobot/ChestShop/Dependencies.java @@ -111,7 +111,7 @@ private static boolean loadEconomy() { } 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 @@ private enum Dependency { this.author = author; } } - + @EventHandler(priority = EventPriority.MONITOR) public void onEnable(PluginEnableEvent event) { Plugin plugin = event.getPlugin(); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/EconomyAdapter.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/EconomyAdapter.java index 60d57d24e..fa38ed09a 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/EconomyAdapter.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/EconomyAdapter.java @@ -11,11 +11,13 @@ 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); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/ReserveListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/ReserveListener.java index 89b2b0bc4..e38114f0a 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/ReserveListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/ReserveListener.java @@ -33,7 +33,10 @@ public ReserveListener(@Nullable EconomyAPI api) { } @Override - public ProviderInfo getProviderInfo() { + public @Nullable ProviderInfo getProviderInfo() { + if (economyAPI == null) { + return null; + } return new ProviderInfo(economyAPI.name(), economyAPI.version()); } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java index 71a4b22db..4ab8761e9 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java @@ -15,6 +15,7 @@ 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 @@ private boolean checkSetup() { } @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 void onServiceUnregister(ServiceUnregisterEvent event) { } } + @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)) {