MilkBowl / VaultAPI

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

no Vault dependency found! #161

Open JusteLoneWolf opened 1 year ago

JusteLoneWolf commented 1 year ago

Hi, i have a problem with vault

When i start my server my plugins don't detect Vault but Vault plugins it's present on my plugins folder

image VaultEconomy is my plugin

image image

package fr.lonewolf.vaulteconomy;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

public final class VaultEconomy extends JavaPlugin {

    private static Economy economy = null;

    @Override
    public void onEnable() {
        if (!setupEconomy() ) {
            System.out.println("Disabled due to no Vault dependency found!");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
    }

    private boolean setupEconomy()
    {
        RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
        if (economyProvider != null) {
            economy = economyProvider.getProvider();
        }

        return (economy != null);
    }

    public static Economy getEconomy() {
        return economy;
    }

}

yes it's very basic code for the moment

Anyone know to fix it ?

Geolykt commented 1 year ago

It is generally advisable to question what you see: Why would it be null? Why would there be no registered Service Provider for an Economy? Henceforth, why would there be no Economy or if there is one, why isn't it registered at this point? Could it be that it is registered too late?

My hint: You lack the Plugin that registers the economy. Going from the name of your plugin it seems you don't actually want to obtain the current economy but rather register a new one - in that case follow the necessary steps to register an economy. I suppose you'd need to dig a bit deeper into that as I don't remember an easy to grasp guide anywhere. However the gist is that you need to implement vault's Economy interface and register your instance of Economy via https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/ServicesManager.html#register(java.lang.Class,T,org.bukkit.plugin.Plugin,org.bukkit.plugin.ServicePriority).

In the future, such questions are better off asked in the spigot discord if you are using spigot or the paper discord if using paper. If neither apply or you are not using discord then ordinarily I'd recommend the spigot IRC and a bit of patience but with the current state of things I won't. What I'm getting at is that you (as much as anyone else) should not use this issue tracker for these kinds of questions as you generally get far worse response times (Upwards of a day, potentially even more).