Vault

Vault

7M Downloads

RegisteredServiceProvider not found

Lolmewn opened this issue ยท 4 comments

commented

It appears that this.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); returns null, while it always used to work. My plugin.yml contains depend: [Vault], and I check if the plugin actually exists before I try to find the provider. I'm using v1.4.1-b436, only plugins on the server are Vault, Stats, Achievements and a custom plugin.

commented

Can confirm; having the same issue with my open-source plugin LotteryBox and Vault 1.4.1.

Console output:

[13:29:08 INFO]: [Vault] Loading Vault v1.4.1-b436
[13:29:08 INFO]: [LotteryBox] Loading LotteryBox v0.0.1
[13:29:08 INFO]: [Vault] Enabling Vault v1.4.1-b436
[13:29:08 INFO]: [Vault] [Permission] SuperPermissions loaded as backup permission system.
[13:29:08 INFO]: [Vault] Enabled Version 1.4.1-b436

[...]

[13:29:12 INFO]: [LotteryBox] Enabling LotteryBox v0.0.1
[13:29:12 WARN]: [LotteryBox] Unable to set up economy handler - Vault Economy service not found!

LotteryBox.java

    private boolean setupEconomy() {
        if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
            this.getLogger().warning("Unable to find the 'Vault' plugin. Money rewards will be unavailable.");
            return false;
        }

        this.economy = new Economy(this);
        this.economy.setup();

        return true;
    }

Economy.java

package me.gserv.lotterybox.economy;

import me.gserv.lotterybox.LotteryBox;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;

public class Economy {

    private final LotteryBox plugin;
    private net.milkbowl.vault.economy.Economy economy;

    public Economy(LotteryBox plugin) {
        this.plugin = plugin;
    }

    public boolean setup() {
        RegisteredServiceProvider<net.milkbowl.vault.economy.Economy> economyProvider
                = this.plugin.getServer().getServicesManager().getRegistration(
                    net.milkbowl.vault.economy.Economy.class
                );
        if (economyProvider != null) {
            this.economy = economyProvider.getProvider();
            return true;
        }

        return false;
    }

    public void addReward(Player player, int reward) {
        if (!this.economy.hasAccount(player)) {
            this.economy.createPlayerAccount(player);
        }

        this.economy.depositPlayer(player, reward);
    }
}
commented

We're so funny - no economy plugin installed.

commented

Confirmed. Would be a good idea to put that info on the BukkitDev page.

commented

A+