After adding economy/vault prices my plugin doesn't run the command.

Discussion in 'Spigot Plugin Development' started by Loyfe_, Jun 2, 2017.

  1. https://pastebin.com/aX9t3ffs
    Latest: https://pastebin.com/QVyKzPa5
    After adding that economy/vault prices to the kit, i recieve internal errors in game.
    My error:
    Code (Text):
    org.bukkit.command.CommandException: Unhandled exception executing command 'monsterkit' in plugin MonstersDelight v0.22 (Pre-Alpha)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_131]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_131]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
    Caused by: java.lang.NullPointerException
        at com.life.monstersdelight.PCommands.onCommand(PCommands.java:67) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot1.8.8.jar:git-Spigot-db6de12-18fbb24]
        ... 15 more
     
  2. The error is in PCommands on line 67. You only provided the code for PCommands2.

    Please show us the code for PCommands or try figguring out yourself what can be null on line 67 in PCommands.
     
    • Like Like x 1
  3. Okay.
    Here it is.
    Code (Text):
    package com.life.monstersdelight;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Fireball;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    import com.massivecraft.factions.entity.Faction;
    import com.massivecraft.factions.entity.MPlayer;

    import net.md_5.bungee.api.ChatColor;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;

    public class PCommands implements CommandExecutor{
     
    public PCommands(Main main) {

        }
    public PCommands(VaultHook vaulthook) {

        }


    private Economy econ = null;

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
     
        Player player = (Player) sender;

        if (sender instanceof Player) {
     
     
            String lowerCmd = cmd.getName().toLowerCase();
         
            switch (lowerCmd) {
             
                case "fcheck":
             
                    MPlayer mp = MPlayer.get(player);
                    Faction faction = mp.getFaction();
         
                    if ( !faction.getName().equals("&2Wilderness") ) {
                        player.sendMessage(ChatColor.GREEN + "You are in a faction!");
                        return true;
                 
                    } else {
                        player.sendMessage(ChatColor.RED + "You are factionless!");
                        return true;
                }
             
                case "monsterkit":
             
                if (args.length ==1) {
                     
                      Line 67:  switch (args[0].toLowerCase()) {
                         
                        case "goblin":
                            if(sender.hasPermission("monstersdelight.kit.goblin")){
                            EconomyResponse r = econ.withdrawPlayer(player, 400);
                            if(r.transactionSuccess()) {
                            player.sendMessage(ChatColor.GREEN + "You have recieved Goblin Kit!");
                            Inventory invgoblinsword = player.getInventory();
                            ItemStack itemgoblinsword = new PItemMaker().buildGoblinSword(1);
                            ItemStack itemgoblinshelmet = new PItemMaker().buildGoblinHelmet(1);
                            ItemStack itemgoblinschestplate = new PItemMaker().buildGoblinChestplate(1);
                            ItemStack itemgoblinsleggings = new PItemMaker().buildGoblinLeggings(1);
                            ItemStack itemgoblinsboots = new PItemMaker().buildGoblinBoots(1);
                            invgoblinsword.addItem(itemgoblinsword);
                            invgoblinsword.addItem(itemgoblinshelmet);
                            invgoblinsword.addItem(itemgoblinschestplate);
                            invgoblinsword.addItem(itemgoblinsleggings);
                            invgoblinsword.addItem(itemgoblinsboots);
                            return true;
                                } else {
                                    player.sendMessage(ChatColor.RED + "You do not have enough money, or there is an internal error.");
                                    return true;
                                }
                            }
    Also, every other command works. Like fcheck since it does not have an economy price.
     
  4. Are you sure about this beeing line 67? I think that this is the culprint:
    I don't see you initializing econ anywhere.
     
  5. I am initializing Econ in another class. Does that effect anything?
     
  6. econ is a private field and I can't see any getter/setter. How are you initializing it in another class then?
     
  7. Ahh, okay. I'll initialize Economy in the same class. I have made Economy Initialize in another class, here's the link to it:https://pastebin.com/yn4iD6hn