Simple command plugin doesnt work (returns command name)

Discussion in 'Plugin Development' started by Lanuk, Jan 21, 2012.

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

    Lanuk

    Hello, I am attempting to make a simple plugin that restores your food bar. When I export it and use it on my 1.1 server (the bukkit version im using to develop my plugin is 1.0 because the 1.1 version doesnt work for some reason), it starts up fine without errors, but when I use a command, instead of healing my foodbar/sending me a message, it just displays the command name on my screen. Here is my code: (I am fairly sure my yml is correct)

    Code:
    package com.rocketmail.lanuk.FoodBarRestore;
     
    import java.util.logging.Logger;
     
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class FoodBarRestore extends JavaPlugin{
     
        Logger log = Logger.getLogger("Minecraft");
       
        @Override
        public void onDisable() {
            log.info("FoodBarRestore disabled.");
           
        }
     
        @Override
        public void onEnable() {
            log.info("FoodBarRestore enabled!");
           
        }
       
        public boolean onCommand(Command cmd, Player p){
            if(cmd.getName().equalsIgnoreCase("fbrestore")){
                p.setFoodLevel(10);
                return true;
            }
            if(cmd.getName().equalsIgnoreCase("fbcheck")){
                p.sendMessage("Your food level is " + p.getFoodLevel());
           
                if (p.getFoodLevel() < 4){
                    p.sendMessage("It would be a good idea to restore now.");
                }
               
                return true;
            }
            return false;
        }
    }
    
    Could someone please tell me what I am doing wrong? Thanks in advance!
     
  2. public boolean onCommand(Command cmd, Player p){ <- this is wrong.
     
  3. Offline

    Lanuk

    Ah sorry im kind of a noob at this, what exactly is wrong about it?
     
  4. public boolean onCommand(CommandSender sender, Command cmd,
    String command, String[] args) {
     
  5. Offline

    ItsHarry

    It's supposed to be

    onCommand(CommandSender sender, Command cmd, String label, String[] args)
     
  6. Offline

    Lanuk

    Ok thanks guys, works now! One more question though, how do I make this work with permissions. I have my permission nodes in my plugin.yml, but im guessing ill have to do more to make it PermissionsBukkit compatible.. right?
     
  7. Offline

    iffa

    player.hasPermission("permission.node")

    UNLESS the permission is defined under the command, i.e.
    Code:
    commands:
        command:
            permission: permission.node
    
     
  8. Code:java
    1. if(!sender.hasPermission("your.node"))
    2. {
    3. sender.sendMessage("No permission!");
    4. return true;
    5. }
     
  9. Offline

    Lanuk

    Ah thanks guys, I appreciate the help. Everything works now :D
     
Thread Status:
Not open for further replies.

Share This Page