My Plugin Doesn't Execute

Discussion in 'Plugin Development' started by mymycool9, Dec 12, 2012.

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

    mymycool9

    So this is my first time making a bukkit plugin, and whenever I export it into my plugins folder on my Bukkit server, and try to do the command (e.g. heal) /heal, it just outputs /heal [player]. main.java:
    Code:
    package com.gmail.mycorgaming.MMCommands;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public final class main extends JavaPlugin
    {
        public boolean onCommand(CommandSender sender, Command cmd, String label, Player target, String[] args){
            if(cmd.getName().equalsIgnoreCase("Repleat")){
                target.setFoodLevel(20);
            }
            if(cmd.getName().equalsIgnoreCase("Starve")){
                target.setFoodLevel(0);
            }
            if(cmd.getName().equalsIgnoreCase("Murder")){
                target.setHealth(0);
            }
            if(cmd.getName().equalsIgnoreCase("Heal")){
                target.setHealth(20);
            }
            if(cmd.getName().equalsIgnoreCase("HighLevel")){
                target.setLevel(100);
            }
            return true;
               
        }
    }
    I have a plugin.yml that is working.

    Thanks in advanced!
     
  2. Offline

    fireblast709

  3. Offline

    Polaris29

    You don't get the first argument of the command from the method's parameters. You instead get the arguments from the String[] args, so the name of the player would be args[0] so get rid of "Player target"

    You can use this to get Player from String: Player target = Bukkit.getServer().getPlayer(args[0]);
    You also want to check to see if Player target is null, because it will be null if the player is not found on the server.

    Also, I think you need an onEnable() and onDisable()
    And you might or might not need @Override before the method
     
  4. Offline

    fireblast709

    to clarify: the onCommand method should look like this
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
     
  5. Offline

    mymycool9

    Thanks both of you so much!!! It works!!!
     
  6. Offline

    chenr1

    Mine is still not working. When I type the command it just spits the command back.
     
  7. Offline

    makskay

    "Spitting the command back" means that your onCommand method is returning false (indicating that the command was typed incorrectly and the player should be provided with the correct syntax.) The onCommand should return true if your plugin was able to process the command.

    If you want any further help, we need to see the contents of your onCommand method.
     
  8. Offline

    chenr1

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
     
        if(cmd.getName().equalsIgnoreCase("blue")){
            TeamBlue.add(sender.getName());
            TeamRed.remove(sender.getName());
            sender.sendMessage(ChatColor.BLUE + "Team Switched To Blue, game will start soon.");
            return true;
        }
     
     
     
     
     
    }
    
    Thanks For the help, this just started happening. After I Controlled + C The code from a text file.
     
  9. Offline

    makskay

  10. Offline

    CorrieKay

    I would like to just quickly clarify that returning false/true is not restricted to this. I always return true on all of my commands, as i prefer handling error information on my own. Returning false tells bukkit to send you the usage string of the command, while true means not to.
    If the command is returning false, that means that his plugin.yml is written, and his command has been registered.
     
  11. Offline

    makskay

    Yeah -- I considered mentioning that you can return true if you want to handle errors your own way, but decided not to muddy the waters. Thanks for cleaning up after me :p
     
Thread Status:
Not open for further replies.

Share This Page