Plugin not hooking into Vault properly

Discussion in 'Spigot Plugin Development' started by StereoN, Feb 10, 2019.

  1. Hello, I was trying to launch my plugin which handles Economy (Hooks into vault), but when I tried to let other plugins use my economy, it keeps giving the respective plugin a NPE on the line where the withdrawl of money is handled. I've put debug messages in my code, but none of them show up, so I'm starting to think I haven't registered my economy well, and I don't quite know what's missing.

    Registering it in my onEnable():
    Code (Text):

    this.getServer().getServicesManager().register(Economy.class, new VaultHook(), this, ServicePriority.Normal);
     
    My withdraw method from the VaultHook() wihch extends AbstractEconomy (Tried with simple Economy, same result):
    Code (Text):

    public EconomyResponse withdrawPlayer(OfflinePlayer p, double moneyToTake)
    {
     
        Bukkit.getConsoleSender().sendMessage("sss");

        File dataf = new File(Main.plugin.getDataFolder() + File.separator + "data.yml");

        YamlConfiguration data = YamlConfiguration.loadConfiguration(dataf);

        if(p == null)
        {
            Bukkit.getConsoleSender().sendMessage("aaa");
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Jucatorul este null");
        }

        Bukkit.getConsoleSender().sendMessage("bbb");

        if(!hasAccount(p))
        {
            return new EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "Jucatorul nu este inregistrat!");
        }

        Bukkit.getConsoleSender().sendMessage("ccc");

        if(moneyToTake <= 0)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Nu poti depozita fonduri negative");
        }

        Bukkit.getConsoleSender().sendMessage("ddd");

        if(data.getInt(p.getUniqueId().toString() + ".money") < moneyToTake)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Jucatorul nu are suficienti bani");
        }

        Bukkit.getConsoleSender().sendMessage("eee");

        moneyToTake = Math.abs(moneyToTake);

        String uuid = p.getUniqueId().toString();

        int money = data.getInt(uuid + ".money");

        Bukkit.getConsoleSender().sendMessage(Integer.toString(money)); //debug

        double removemoney = money - moneyToTake;

        data.set(uuid + ".money", Double.valueOf(removemoney));

        return new EconomyResponse(moneyToTake, getBalance(p), EconomyResponse.ResponseType.SUCCESS, "");
    }
     
    Any help is great, I've been struggling with this for some time :/
     
    #1 StereoN, Feb 10, 2019
    Last edited: Feb 10, 2019
  2. I know the link, I've looked into it several times, and the method setupEconomy() is for plugins which want to use Vault to handle economy, from what I've seen by now. If you want your plugin to handle economy, you need to register your class, like I did. At least that's what I've understood from other threads and open-source plugins..

    https://www.spigotmc.org/threads/vault-integration.356552/#post-3289980
     
  3. Can you show your full eco class?
     
    • Like Like x 1
  4. If not resolved by the time I’m home I’ll post what I’ve got in my races plugin here.
     
    • Friendly Friendly x 1
  5. Sure, I'm at school right now, but I'll show it as soon as I get home.
     
  6. VaultHook class:

    Code (Text):


    public class VaultHook extends AbstractEconomy
    {

    @Override
        public boolean createPlayerAccount(String name)
        {

            Player p = Bukkit.getPlayer(name);

            File dataf = new File(Main.plugin.getDataFolder() + File.separator + "data.yml");

            YamlConfiguration data = YamlConfiguration.loadConfiguration(dataf);

            if(data.getString(p.getUniqueId().toString()) == null)
            {
                return true;
            }

            Data.createAccount(p);

            return false;
        }

        @Override
        public boolean createPlayerAccount(OfflinePlayer arg0)
        {
            return createPlayerAccount(arg0);
        }

        @Override
        public boolean createPlayerAccount(String arg0, String arg1)
        {
            return createPlayerAccount(arg0);
        }

        @Override
        public boolean createPlayerAccount(OfflinePlayer arg0, String arg1)
        {
            return createPlayerAccount(arg0);
        }

        @Override
        public String currencyNamePlural()
        {
            return "";
        }

        @Override
        public String currencyNameSingular()
        {
            return "";
        }

        @Override
        public EconomyResponse depositPlayer(String name, double moneyToGive)
        {

            return depositPlayer(Bukkit.getOfflinePlayer(name), moneyToGive);
        }

        @Override
        public EconomyResponse depositPlayer(OfflinePlayer p, double moneyToGive)
        {
            if(!hasAccount(p))
            {
                return new EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "Jucatorul nu este inregistrat!");
            }


            if(moneyToGive <= 0)
            {
                return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Nu poti depozita fonduri negative");
            }

            if(p == null)
            {
                return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Jucatorul este null");
            }

            moneyToGive = Math.abs(moneyToGive);

            String uuid = p.getUniqueId().toString();

            File dataf = new File(Main.plugin.getDataFolder() + File.separator + "data.yml");

            YamlConfiguration data = YamlConfiguration.loadConfiguration(dataf);

            int money = data.getInt(uuid + ".money");

            double addmoney = money + moneyToGive;

            data.set(uuid + ".money", Double.valueOf(addmoney));

            return new EconomyResponse(moneyToGive, getBalance(p), EconomyResponse.ResponseType.SUCCESS, "");
        }

        @Override
        public EconomyResponse depositPlayer(String arg0, String arg1, double arg2)
        {
            return depositPlayer(arg0, arg2);
        }

        @Override
        public EconomyResponse depositPlayer(OfflinePlayer arg0, String arg1, double arg2)
        {
            return depositPlayer(arg0, arg2);
        }

        @Override
        public String format(double arg0)
        {

            double x = API.round(arg0);
            String s = Double.toString(x);

            return s;

        }

        @Override
        public int fractionalDigits()
        {
            return 0;
        }

        @Override
        public double getBalance(String arg0)
        {

            File dataf = new File(Main.plugin.getDataFolder() + File.separator + "data.yml");

            YamlConfiguration data = YamlConfiguration.loadConfiguration(dataf);

            OfflinePlayer p = Bukkit.getOfflinePlayer(arg0);

            String uuid = p.getUniqueId().toString();

            return data.getInt(uuid + ".money");

        }


        @Override
        public EconomyResponse withdrawPlayer(String name, double amount)
        {
            return withdrawPlayer(Bukkit.getOfflinePlayer(name), amount);
        }

        Plugin pl = Bukkit.getServer().getPluginManager().getPlugin("EssentialsLite");

        @Override
        public EconomyResponse withdrawPlayer(OfflinePlayer p, double moneyToTake)
        {

            Bukkit.getConsoleSender().sendMessage("sss");

            File dataf = new File(pl.getDataFolder() + File.separator + "data.yml");

            YamlConfiguration data = YamlConfiguration.loadConfiguration(dataf);

            if(p == null)
            {
                Bukkit.getConsoleSender().sendMessage("aaa");
                return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Jucatorul este null");
            }

            Bukkit.getConsoleSender().sendMessage("bbb");

            if(!hasAccount(p))
            {
                return new EconomyResponse(0.0, 0.0, EconomyResponse.ResponseType.FAILURE, "Jucatorul nu este inregistrat!");
            }

            Bukkit.getConsoleSender().sendMessage("ccc");

            if(moneyToTake <= 0)
            {
                return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Nu poti depozita fonduri negative");
            }

            Bukkit.getConsoleSender().sendMessage("ddd");

            if(data.getInt(p.getUniqueId().toString() + ".money") < moneyToTake)
            {
                return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Jucatorul nu are suficienti bani");
            }

            Bukkit.getConsoleSender().sendMessage("eee");

            moneyToTake = Math.abs(moneyToTake);

            String uuid = p.getUniqueId().toString();

            int money = data.getInt(uuid + ".money");

            Bukkit.getConsoleSender().sendMessage(Integer.toString(money));

            double removemoney = money - moneyToTake;

            data.set(uuid + ".money", Double.valueOf(removemoney));

            return new EconomyResponse(moneyToTake, getBalance(p), EconomyResponse.ResponseType.SUCCESS, "");
        }

        @Override
        public EconomyResponse withdrawPlayer(String arg0, String arg1, double arg2)
        {
            return withdrawPlayer(arg0, arg2);
        }

        @Override
        public EconomyResponse withdrawPlayer(OfflinePlayer arg0, String arg1, double arg2)
        {
            return withdrawPlayer(arg0, arg2);
        }

        @Override
        public double getBalance(OfflinePlayer arg0)
        {
            return getBalance(arg0.getName());
        }

        @Override
        public double getBalance(String arg0, String arg1)
        {
            Player p = Bukkit.getPlayer(arg0);
            return getBalance(p);
        }

        @Override
        public double getBalance(OfflinePlayer arg0, String arg1)
        {
            return getBalance(arg0);
        }

        @Override
        public List<String> getBanks()
        {
            return new ArrayList<String>();
        }

        @Override
        public String getName()
        {
            return "Economy";
        }

        @Override
        public boolean has(String arg0, double arg1)
        {

            Player p = Bukkit.getPlayer(arg0);

            File dataf = new File(Main.plugin.getDataFolder() + File.separator + "data.yml");

            YamlConfiguration data = YamlConfiguration.loadConfiguration(dataf);

            if (data.getInt(p.getUniqueId().toString() + ".money") >= arg1) {
                return true;
            }

            return false;

        }

        @Override
        public boolean has(OfflinePlayer arg0, double arg1)
        {

            File dataf = new File(Main.plugin.getDataFolder() + File.separator + "data.yml");

            YamlConfiguration data = YamlConfiguration.loadConfiguration(dataf);

            if (data.getInt(arg0.getUniqueId().toString() + ".money") >= arg1) {
                return true;
            }

            return false;
        }

        @Override
        public boolean has(String arg0, String arg1, double arg2)
        {
            return has(arg0, arg2);
        }

        @Override
        public boolean has(OfflinePlayer arg0, String arg1, double arg2)
        {
            return has(arg0, arg2);
        }

        @Override
        public boolean hasAccount(String arg0)
        {
            Player p = Bukkit.getPlayer(arg0);
            File dataf = new File(Main.plugin.getDataFolder() + File.separator + "data.yml");

            YamlConfiguration data = YamlConfiguration.loadConfiguration(dataf);

            if(data.getString(p.getUniqueId().toString()) == null)
            {
                return false;
            }
            return true;
        }

        @Override
        public boolean hasAccount(OfflinePlayer arg0)
        {

            return hasAccount(arg0.getName());
        }

        @Override
        public boolean hasAccount(String arg0, String arg1)
        {
            return hasAccount(arg0);
        }

        @Override
        public boolean hasAccount(OfflinePlayer arg0, String arg1)
        {
            return hasAccount(arg0);
        }

        @Override
        public boolean isEnabled()
        {
            if(Main.plugin != null)
            {
                return true;
            }

            return false;
        }

        public EconomyResponse bankBalance(String arg0)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse bankDeposit(String arg0, double arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse bankHas(String arg0, double arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse bankWithdraw(String arg0, double arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse createBank(String arg0, String arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse createBank(String arg0, OfflinePlayer arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse deleteBank(String arg0)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        @Override
        public boolean hasBankSupport()
        {
            return false;
        }

        public EconomyResponse isBankMember(String arg0, String arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse isBankMember(String arg0, OfflinePlayer arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse isBankOwner(String arg0, String arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

        public EconomyResponse isBankOwner(String arg0, OfflinePlayer arg1)
        {
            return new EconomyResponse(0, 0, EconomyResponse.ResponseType.NOT_IMPLEMENTED, "Momentan nu suportam conturi bancare!");
        }

    }
     
     
  7. Can you show us the error?
     
    • Friendly Friendly x 1
  8. Sure. From what I've seen from the code, it points to withdrawPlayer() in one of its methods.
    The problem is not AuctionHouse, because if I put another plugin to handle economy, it works perfectly.
    Also, the debug mode of Vault seems not to work, making everything harder :/

    Code (Text):

    [10:16:45] [Server thread/INFO]: Pablito issued server command: /ah sell 1
    [10:16:45] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'ah' in plugin AuctionHouse v3.3
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:649) ~[spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1397) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1232) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        at java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.NullPointerException
        at net.cfilatov.auctionhouse.commands.CommandHandler.handleAuctionSell(CommandHandler.java:100) ~[?:?]
        at net.cfilatov.auctionhouse.commands.CommandHandler.onCommand(CommandHandler.java:68) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.2.jar:git-Spigot-3d850ec-809c399]
        ... 15 more
     
     
  9. If you know how to read Stack Traces, it's happening in your CommandHandler class at line 68, and in the method handleAuctionSell at line 100.
     
  10. For your interest, that's not my plugin. The error points to the withdrawPlayer() method which is not working for some reason as debug messages are not shown. No direct error on my plugin, my plugin is causing the error by not hooking into vault as it should be.
     
    #11 StereoN, Feb 12, 2019
    Last edited: Feb 13, 2019

Share This Page