java.lang.NullPointerException

Discussion in 'Bukkit Help' started by jblade123, Jul 4, 2016.

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

    jblade123

    Help I can't figure out how to fix this error. This is my first plugin.

    package me.jblade.kits;



    import org.bukkit.ChatColor;

    import org.bukkit.Material;

    import org.bukkit.command.Command;

    import org.bukkit.command.CommandSender;

    import org.bukkit.enchantments.Enchantment;

    import org.bukkit.entity.Player;

    import org.bukkit.inventory.ItemStack;

    import org.bukkit.plugin.java.JavaPlugin;



    public class Test extends JavaPlugin {

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)

    {

    Player p = (Player)sender;


    if(cmd.getName().equalsIgnoreCase("pvp")){

    p.sendMessage(ChatColor.AQUA + "You have obtained the PvP kit!");

    ItemStack dsword = new ItemStack(Material.DIAMOND_SWORD);

    dsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);

    p.getInventory().addItem(dsword);

    p.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));

    p.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));

    p.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));

    p.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));

    for (ItemStack item : p.getInventory().getContents()) {

    if (item == null) {

    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));

    }

    }






    }


    returnfalse;


    }



    }
     
  2. Offline

    mc_myster

    @jblade123 You have posted this 2 times and like i said in your last post, you put this in the wrong section.
     
  3. Offline

    ipodtouch0218

    Use [ code] [ /code] tags to format code.
    Do you have a Stack Trace (error log?)[/code]


    EDIT:
    Don't automatically assign sender to a Player.
    If the console uses the command, it will return a ClassCastException.

    Only assign sender to a Player if your command is executed. It is unnecessary and just uses data.
     
Thread Status:
Not open for further replies.

Share This Page