Skip to content

Commit

Permalink
Fix Vault No Economy Plugin Found Error (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerMistkaefer authored Dec 17, 2024
1 parent 1e40caa commit c5fc9f7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/main/java/com/Acrobot/ChestShop/ChestShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -335,7 +337,7 @@ private void registerEvents() {
registerEvent(new com.Acrobot.ChestShop.Plugins.ChestShop()); //Chest protection

registerEvent(new Dependencies());

registerEvent(new NameManager());

registerPreShopCreationEvents();
Expand Down Expand Up @@ -536,6 +538,16 @@ public static DrilldownPie createStaticDrilldownStat(String statId, String value
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};
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/Acrobot/ChestShop/Dependencies.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static boolean loadEconomy() {
}

ChestShop.getMetrics().addCustomChart(ChestShop.createStaticDrilldownStat("economyAdapter", plugin, Bukkit.getPluginManager().getPlugin(plugin).getDescription().getVersion()));

Check warning on line 113 in src/main/java/com/Acrobot/ChestShop/Dependencies.java

View workflow job for this annotation

GitHub Actions / qodana

Nullability and data flow problems

Method invocation `getDescription` may produce `NullPointerException`
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!");
Expand Down Expand Up @@ -256,7 +256,7 @@ private enum Dependency {
this.author = author;
}
}

@EventHandler(priority = EventPriority.MONITOR)
public void onEnable(PluginEnableEvent event) {
Plugin plugin = event.getPlugin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit c5fc9f7

Please sign in to comment.