1.8.8 Hook into Vault not working

Discussion in 'Spigot Plugin Development' started by pascalwebtm, Feb 20, 2020.

Thread Status:
Not open for further replies.
  1. Hi,

    Im currently making a plugin, which opens an inventory where you can buy a crate.
    For that, I want to take money from the players balance. I use EssentialsX and I have Vault installed.
    I used this https://www.spigotmc.org/wiki/hook-into-vault/ tutorial for vault, but it doesnt work.

    I get this error when reloading:

    Code (Text):
    [09:23:03 INFO]: [Vault] [Economy] Essentials Economy found: Waiting
    [09:23:03 INFO]: [Vault] [Permission] SuperPermissions loaded as backup permission system.
    [09:23:03 INFO]: [Vault] Enabled Version 1.7.2-b107
    [09:23:03 INFO]: [AdvancedLobby] Enabling AdvancedLobby v1.0.6
    [09:23:03 INFO]: [AdvancedLobby] Loading files..
    [09:23:03 INFO]: [CaseShop] Enabling CaseShop v1.0
    [09:23:03 ERROR]: Error occurred while enabling CaseShop v1.0 (Is it up to date?)
    java.lang.NullPointerException
            at eu.pascalweb.caseshop.Main.setupChat(Main.java:54) ~[?:?]
            at eu.pascalweb.caseshop.Main.onEnable(Main.java:30) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
    I already know from these lines:
    at eu.pascalweb.caseshop.Main.setupChat(Main.java:54) ~[?:?]
    at eu.pascalweb.caseshop.Main.onEnable(Main.java:30) ~[?:?]
    that my economy is probably "null" but I dont know how to resolve it, since I did everything like in the tutorial.

    This is my Main.java:

    Code (Java):
    package eu.pascalweb.caseshop;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;

    import eu.pascalweb.caseshop.command.openUI;
    import eu.pascalweb.caseshop.listener.invClickListener;
    import eu.pascalweb.caseshop.ui.UI;
    import net.milkbowl.vault.chat.Chat;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.permission.Permission;

    public class Main extends JavaPlugin {
       
        private Economy econ;
        private Permission perms;
        private Chat chat;
       
        @Override
        public void onEnable() {
           
            if (!setupEconomy()) {
                this.getLogger().severe("Please install the Plugin Vault. Disabling CaseShop...");
                Bukkit.getPluginManager().disablePlugin(this);
                return;
            }
           
            this.setupPermissions();
            this.setupChat();
           
            new openUI(this);
            new invClickListener(this);
           
            UI.initialize();
           
        }
       
        private boolean setupEconomy() {
            if (Bukkit.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;
        }

        private boolean setupChat() {
            RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
            chat = rsp.getProvider();
            return chat != null;
        }

        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            perms = rsp.getProvider();
            return perms != null;
        }

        public Economy getEconomy() {
            return econ;
        }

        public Permission getPermissions() {
            return perms;
        }

        public Chat getChat() {
            return chat;
        }


    }
     
     
  2. Hmm so.. ur checking if setupEconomy is false but it always returns false?
     
    • Useful Useful x 1
  3. I don’t know... I just used the code from the official tutorial. I thought it would be right.
    What do I have to change?
     
  4. You probably need to add a null check for the rsp to make sure it isn't null. Make sure you also depend on Vault in your plugin.yml, cause this issue may occur because Vault is loading after your plugin.
     
    • Useful Useful x 1
    • Useful Useful x 1
  5. Ok I tried that now. Sadly, im still getting the Error...
    Code (Text):
    [11:26:02 INFO]: [CaseShop] Enabling CaseShop v1.0
    [11:26:02 ERROR]: Error occurred while enabling CaseShop v1.0 (Is it up to date?)
    java.lang.NullPointerException
            at eu.pascalweb.caseshop.Main.setupChat(Main.java:60) ~[?:?]
            at eu.pascalweb.caseshop.Main.onEnable(Main.java:34) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [Spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
    This is my new Main.java:

    Code (Java):
    package eu.pascalweb.caseshop;


    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;

    import eu.pascalweb.caseshop.command.openUI;
    import eu.pascalweb.caseshop.listener.invClickListener;
    import eu.pascalweb.caseshop.ui.UI;
    import net.milkbowl.vault.chat.Chat;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.permission.Permission;

    public class Main extends JavaPlugin {
     
        private static Economy econ = null;
        private static Permission perms = null;
        private static Chat chat = null;
     
        @Override
        public void onDisable() {
            this.getLogger().severe(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
        }
     
        @Override
        public void onEnable() {
         
              if (!setupEconomy() ) {
                    this.getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                    getServer().getPluginManager().disablePlugin(this);
                    return;
                }
                setupPermissions();
                setupChat();
         
            new openUI(this);
            new invClickListener(this);
         
            UI.initialize();
         
        }
     
        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;
        }
     
        private boolean setupChat() {
            RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
            chat = rsp.getProvider();
            return chat != null;
        }
     
        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            perms = rsp.getProvider();
            return perms != null;
        }


    }
     
     
  6. I have added a depend now for Vault and Essentials. Still getting the Error.
     
  7. Do not forget to add Vault as an plugin to your server.
    Code (Java):
    RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
    Code (Java):
    RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
    These two lines can return null if Vault is not present. Add a null-check.
     
    • Useful Useful x 1
  8. How do I add that null Check?

    I have Vault on my Server of course.
     
  9. Do I just say
    Code (Java):
    if (econ == null){
         return;
    }
    ?
     
  10. Setup permissions and chat can throw a Nullpointerexception as well. RegisteredServiceProvider can be null I guess.
     
    • Useful Useful x 1
  11. Ok so the problem seems to be "setupChat".
    I have added following lines to both "setupChat" and "setupEconomy":

    Code (Java):
            if (econ == null) {
                this.getLogger().severe("Econ is null. Disabling CaseShop...");
            } else {
                this.getLogger().severe("Econ is not null.");
            }
    and
    Code (Java):
            if (chat == null) {
                this.getLogger().severe("Chat is null. Disabling CaseShop...");
            } else {
                this.getLogger().severe("Chat is not null.");
            }
    So when reloading I only get "[CaseShop] Econ is not null." in the Chat and then the Error.
    Since Chat seems to be "null" should it not show the "Chat is null. Disabling CaseShop..." message?
     
  12. Ok it works!
    I only had to install PermissionsEx...

    Thanks for the help.
     
Thread Status:
Not open for further replies.