Command Registering??

Discussion in 'Plugin Development' started by MaxFireIce, Dec 1, 2016.

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

    MaxFireIce

    Okay, so, I obviously know how to register commands. However, it messed up for some reason and i cant find out why.
    Code:
    java.lang.NullPointerException
            at cardbattles.main.Main.registerCommands(Main.java:34) ~[?:?]
            at cardbattles.main.Main.onEnable(Main.java:23) ~[?:?]
    I'm getting that error when it enables. Here are the lines:
    line 34 is :
    Code:
    getCommand("dartcard").setExecutor(new SummonCard());
    line 23 is just registtering the command in the onEnable() thing.

    Help?
     
  2. Offline

    xPlumpOrange

    Can you give us all your code for all your classes, and can you include the full error message?
     
  3. Offline

    Zombie_Striker

    @MaxFireIce
    That mist likely means there has been an Initialization problem with the SummonCard class. Post that class.

    [Edit]@xPlumpOrange We do not need All of his classes. We just need the ones that are relevant (which world be the SummonCard class).
     
    Last edited: Dec 1, 2016
  4. Online

    timtower Administrator Administrator Moderator

    @MaxFireIce While at it, could you also post your plugin.yml?
     
  5. Offline

    Lordloss

    @xPlumpOrange After reading your previous bunch of comments, i recommend you not to try to help other people fixing their code. Not until you have an sufficient basic knowledge of Java & Bukkit yourself.
     
  6. Offline

    MaxFireIce

    @timtower
    Code:
    commands:
      dartcard:
        description: test for summoning the dart card
    Code:
    package cardbattles.main;
    
    import java.util.Arrays;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class SummonCard implements CommandExecutor{
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
            if (!(sender instanceof Player)){
                sender.sendMessage(ChatColor.RED + "You must be a player to use this command!");
                return false;
            } else {
         
            Player player = (Player) sender;
            ItemStack dartCard = Main.common;
            ItemMeta dartCardMeta = dartCard.getItemMeta();
            dartCardMeta.setLore(Arrays.asList("Shoots a dart", "at your foe"));
            dartCardMeta.setDisplayName(ChatColor.AQUA + "Dart");
            dartCard.setItemMeta(dartCardMeta);
            ItemStack dart = dartCard;
         
            player.getInventory().addItem(dart);
         
            return true;
            }
        }
     
     
    
    }
    
    
    I dont see anything wrong with the class @Zombie_Striker
     
    Last edited: Dec 4, 2016
Thread Status:
Not open for further replies.

Share This Page