Need help with Vault

Discussion in 'Plugin Development' started by Rick221, Oct 29, 2015.

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

    Rick221

    I am trying to make it so that when a player does the command /warband horse it withdraws 5000 dollars and spawns a horse. It is giving a null pointer error which I will put in a spoiler along with my class files

    Error Log (open)

    [06:41:46] [Server thread/INFO]: RickPow issued server command: /warband horse
    [06:41:46] [Server thread/WARN]: java.lang.NullPointerException
    [06:41:46] [Server thread/WARN]: at me.RickPow.CommandHorseEgg.onCommand(CommandHorseEgg.java:21)
    [06:41:46] [Server thread/WARN]: at me.RickPow.Commands.onCommand(Commands.java:37)
    [06:41:46] [Server thread/WARN]: at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    [06:41:46] [Server thread/WARN]: at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140)
    [06:41:46] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:619)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1093)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:953)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
    [06:41:46] [Server thread/WARN]: at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    [06:41:46] [Server thread/WARN]: at java.util.concurrent.FutureTask.run(Unknown Source)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:672)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:628)
    [06:41:46] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:536)
    [06:41:46] [Server thread/WARN]: at java.lang.Thread.run(Unknown Source)



    Commands class which my commands extend:
    Code:
    public class Commands implements CommandExecutor {
       
        public static List<Commands> commands = Collections.synchronizedList(new ArrayList<Commands>());
    
        protected Plugin plug = Main.instance();
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if (args.length == 0)
            {
                sender.sendMessage(ChatColor.RED + "Wrong command usage! Do " + ChatColor.AQUA + "<cmd>");
                return true;
            
            }
           
            boolean didCommand = false;
           
            if (commands.size() == 0)
            {
                registerCommands();
            }
           
            try {
                for (int i = 0;i < commands.size();i++)
                {
                    if (commands.get(i).onCommand(sender, cmd, label, args) == true)
                    {
                        didCommand = true;
                    }
                }
            } catch (Exception ex)
            {
                sender.sendMessage(ChatColor.RED + "Exception occured! Report to a developer. " + ChatColor.RED +
                        ex.getClass().getSimpleName());
                ex.printStackTrace();
                return true;
            }
           
            if (didCommand == false)
            {
                sender.sendMessage(ChatColor.RED + "No such command! Try /<cmd>");
            }
            return true;
        }
       
        public static void registerCommands()
        {
            commands.add(new CommandSpawnGolem());
            commands.add(new CommandSpawnWolf());
            commands.add(new CommandHorseEgg());
            //commands.add(new <class which extends Commands name>());
        }
    
    
    
    }
    

    My Main Class:
    Code:
    public class Main extends JavaPlugin {
       
        public static Economy economy;
       
       
        public void onEnable() {
            Commands.registerCommands();
            getCommand("warband").setExecutor(new Commands());
           
           
              RegisteredServiceProvider<Economy> service = Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
             if(service != null)
                    economy = service.getProvider();
        }
       
        public void onDisable() {
           
           
        }
       
          private boolean setupEconomy() {
                if (getServer().getPluginManager().getPlugin("Vault") == null) {
                    return false;
                }
                RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
                if (rsp == null) {
                    return false;
                }
                economy = rsp.getProvider();
                return economy != null;
            }
    
        public static Plugin instance() {
            // TODO Auto-generated method stub
            return null;
        }
    }

    My Horse Egg command:
    Code:
    public class CommandHorseEgg extends Commands{
        public static Economy economy;
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            Player p = (Player) sender;
            int horseCost = 5000;
            double currentBal = economy.getBalance(p);
            if(p.hasPermission("warband.horse")) {
            if(args[0].equalsIgnoreCase("horse")) {
               
                if(currentBal >= horseCost) {
                EconomyResponse r = economy.withdrawPlayer(p, horseCost); //fix tomorrow
                if(r.transactionSuccess()) {
                p.sendMessage(ChatColor.BLUE + "$5000 withdrawn! You have");
                p.sendMessage(ChatColor.GREEN + "Enjoy your new horse!");
                p.getLocation().getWorld().spawnEntity(p.getLocation(), EntityType.HORSE);
            }
            }
            }
        }
            return true;
    
        }
    }
     
  2. Offline

    teej107

  3. Offline

    WHQ

    @Rick221

    [06:41:46] [Server thread/WARN]: java.lang.NullPointerException

    A Null Pointer Exception in Java is an error which occurs if you try to do something with an object which that is 'null'. when you try to call a method on null or try to access a variable on null you will get this null pointer exception.

    [06:41:46] [Server thread/WARN]: at me.RickPow.CommandHorseEgg.onCommand(CommandHorseEgg.java:21)

    There is something going wrong on line 21 of your code.
     
  4. Offline

    Scimiguy

    And to add to what these two have said:
    If you want any help with something like this, you need to post your entire class, not just cutouts!
     
  5. Offline

    Rick221

    Those are my whole classes, know what your talking about before you sound like an idiot.
     
  6. Offline

    Scimiguy

    Such ignorance

    Where are your imports? Where are your package declarations?
     
  7. Offline

    WHQ

    Lol, this guy! :')
    @Scimiguy is right you know!

    Small piece of live advice: Don't call people idiots when they are trying to help, that's an attitude that won't get you far in life
     
Thread Status:
Not open for further replies.

Share This Page