Solved Adding Balance Issue Vault

Discussion in 'Plugin Development' started by TheNewTao, Dec 15, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    TheNewTao

    Hi,

    I am doing a simple plugin that when you do /voucher test it adds $10 to the player. My code:

    OnEnable:
    Code:
        @Override
        public void onEnable() {
            if (!(new File(getDataFolder(), "config.yml")).exists()) {
                saveDefaultConfig();
            }
            setupEconomy();
            Bukkit.getPluginManager().registerEvents(events, this);
        }
    setupEconomy Method:
    Code:
        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;
        }
    
    // econ is an instance variable
    public static Economy econ = null;
    Command:
    Code:
    else if (args[0].equalsIgnoreCase("test")) {
                            econ.depositPlayer(p, 10.00);
                            p.sendMessage(this.getConfig().get("vouch-number").toString());
                        }
    It is giving me a null pointer error. The error:
    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'voucher' in plugin Voucher v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_60]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_60]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
        at me.thenewtao.voucher.Voucher.onCommand(Voucher.java:148) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-BT45_1.8.8_10.21.jar:git-Bukkit-18fbb24]
        ... 15 more
     
  2. Offline

    Zombie_Striker

    Why is it people like giving "snipits" of code instead of the whole thing. If they gave the whole thing, posts like this would not have to be created.

    What is line 148?
     
  3. Offline

    TheNewTao

    @Zombie_Striker

    Sure I'll give you the whole thing! I just think that some code is irrelevant, but ok. Line 148 is:

    Code:
      econ.depositPlayer(p, 10.00);
    Code:
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
    
    
     
    Last edited: Dec 15, 2015
  4. Offline

    Zombie_Striker

    @TheNewTao
    There is something null on that line:
    1. Econ can be null.
    2. .depositPlayer(p, 10.00); a method and cannot be null.
    3. P can be null, although it is very unlikely.
    Test it. What is it that is null?
     
  5. Offline

    TheNewTao

    I found the mistake, I just wasn't using an economy plugin.
     
Thread Status:
Not open for further replies.

Share This Page