Muli Commands and Error Help

Discussion in 'Plugin Development' started by emericask8ur, Aug 21, 2011.

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

    emericask8ur

    Heres the Command stuff
    Show Spoiler

    @Override


    public boolean
    onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) { if (!(sender instanceof
    Player) || ((Player) sender).isOp()) { if (cmdLabel.equalsIgnoreCase("woodpickaxe"
    )){
    Player p = (Player) sender;
    ItemStack item =new ItemStack(Material.WOOD_PICKAXE
    , 1);
    p.getInventory().addItem(item);
    return true
    ;
    }else
    {
    sender.sendMessage("You do not have permission to do this!"
    );
    }
    }else if(cmdLabel.equalsIgnoreCase("woodhoe"
    )){
    Player p = (Player) sender;
    ItemStack item =new ItemStack(Material.WOOD_HOE
    , 1);
    p.getInventory().addItem(item);
    return true
    ;
    }else
    {
    sender.sendMessage("You do not have permission to do this!"
    ); return true
    ;
    }
    return false
    ;
    }
    }


    Heres the error
    Show Spoiler

    [SEVERE] null loading ToolLast v0.1 (Is it up to date?)
    java.lang.NullPointerException
    at org.bukkit.command.PluginCommandYamlParser.parse(PluginCommandYamlParser.java:26)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:271)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:178)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:161)
    at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:286)
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:273)
    at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:149)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:337)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
     
  2. Offline

    DrBowe

    @emericask8ur
    That can't be all of the stack-trace. Unless I'm missing the part where it actually points to your plugin.
    1) Are you SURE that's the whole error?
    2) If yes, did you register the commands in plugin.yml?
     
  3. Offline

    emericask8ur

    My yml is normal though
     
  4. Offline

    DrBowe

    Ok, that didn't really answer either of those...

    Post your plugin.yml, and also make sure that what you've given me is the full stack-trace (error log)
     
  5. Offline

    iKrazy

    Make sure you're using the exact number of spaces, and no tabs.
     
  6. Offline

    EdTheLoon

    Looking at that stack-trace the error is definitely in your plugin.yml. Could you post it here for us to see?
     
  7. Offline

    CptSausage

    Btw, I think the code is totally wrong as well.
    Here it is formatted:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
            if (!(sender instanceof Player) || ((Player) sender).isOp()) {
                if (cmdLabel.equalsIgnoreCase("woodpickaxe")) {
                    Player p = (Player) sender;
                    ItemStack item = new ItemStack(Material.WOOD_PICKAXE, 1);
                    p.getInventory().addItem(item);
                    return true;
                } else {
                    sender.sendMessage("You do not have permission to do this!");
                }
            } else if (cmdLabel.equalsIgnoreCase("woodhoe")) {
                Player p = (Player) sender;
                ItemStack item = new ItemStack(Material.WOOD_HOE, 1);
                p.getInventory().addItem(item);
                return true;
            } else {
                sender.sendMessage("You do not have permission to do this!");
                return true;
            }
            return false;
        }

    1. if(!(sender instanceof Player) || ((Player)sender).isOp()) {
    That won't work in a single line. Because if the the sender is not 'instanceof' Player, the casting will throw an exception.

    2.if (cmdLabel.equalsIgnoreCase("woodpickaxe")) {
    [...]
    } else {
    [...]You do not have permissions?!?!
    }
    Does that make any sense?

    ... Think you should look over your whole code again, lol.
     
  8. Offline

    emericask8ur

    It formats it dif wen u type it on here
     
  9. Offline

    4am

    No, you're missing a closing curly bracket, and your code is checking if the command was issued by a player, else if (cmdLabel.equalsIgnoreCase("woodhoe")). I'm pretty sure you never meant to check cmdLabel unless you already knew a player issued the command.

    Check your if statements again, your nesting is off; or post the corrected version here if the forums messed the code up - I haven't known them to delete random closing brackets, though. Enclose your code in
    Code:
    //Code formatting by using [code] as a tag
    public void pretendJavaCode() {
       System.out.println("This is just an example!");
    }
    to preserve the formatting.
     
  10. Offline

    emericask8ur

    Trust me im doing that all right and the format is weird when i paste it on bukkit it messed it up thats why it looks dumb

    in my YML?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  11. Offline

    CptSausage

    Than nobody can help you.
     
Thread Status:
Not open for further replies.

Share This Page