MilkBowl / VaultAPI

API Component of Vault
GNU Lesser General Public License v3.0
274 stars 112 forks source link

Vault check failed #128

Closed ZuVEnO closed 3 years ago

ZuVEnO commented 3 years ago

My plugin can't explore Vault plugin, but code included in plugin & as dependencie...

Here's code:

private static final Logger log = Logger.getLogger("Minecraft");
    private static Economy econ = null;

    @Override
    public void onEnable() {
        if (!setupEconomy() ) {
            log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        getCommand("caps").setExecutor(new bottlecaps());
    }

    @Override
    public void onDisable() {

    }

    private boolean setupEconomy() {

        if (getServer().getPluginManager().getPlugin("Vault") == null) {
            return false;
        }
        RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            return false;
        }
        econ = rsp.getProvider();
        return econ != null;
    }

    public static Economy getEconomy() {
        return econ;
    }

Here's plugin.yml

name: Battlecraft
version: '${project.version}'
main: me.zuveno.BattleCraft.DayZ.mainClass
depend:
  - PlaceholderAPI
  - Vault
api-version: 1.16
Geolykt commented 3 years ago

First of all: Do NOT use the internal minecraft logger. Why do people do this?

Additionally: what exactly is the issue here? I personally use

    try {
    Class<?> clazz = net.milkbowl.vault.economy.Economy.class;
        RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(clazz);
        if (economyProvider != null) {
            eco = economyProvider.getProvider();
        }
    } catch (NoClassDefFoundError e) {
        useVault = false;
        eco = null;
        return false;
    }
    useVault = (eco != null);
    return useVault;//Sets useVault to the inverse of whether the Economy is null, and returns it. 

as init code; so pretty much the same as yours.

Another tip: Always init the economy lazily, if the economy plugin loads after you you will have issues, so obtain the economy as late as possible.