Command returns plugin.yml Usage

Discussion in 'Plugin Development' started by Docithe, Feb 2, 2012.

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

    Docithe

    Hey,
    I'm a relatively new plugin developer, so I'm not entirely sure how to deal with this. I'm creating a simple plugin, wherein when you type a command, it returns a message telling you that it went through. here is my code:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            if(commandLabel.equalsIgnoreCase("togglese"))
            {
                sender.sendMessage("The command is working!");
                return true;
            }
            sender.sendMessage("Returned False within code!");
            return false;
        }
    and here's an excerpt from my plugin.yml file:
    Code:
    commands:
      togglese:
        description: Toggle command.
        usage: The command returned the USAGE!
    I've also tried:
    Code:
    commands:
      togglese:
        description: Toggle command.
        usage: The command returned the USAGE!
        default: op
    Every time I type the command, it returns "The command returned the USAGE!".

    Also, the odd naming of the command is relevant to what I intend to turn it into. Right now, I'm just sending messages to get confirmation that it works or doesn't work.

    I've read several other forums about this error, but I have found no solution that works for me. Any advice?
     
  2. Offline

    sds

    Don't know whether this will help:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            if(commandLabel.equalsIgnoreCase("togglese"))
            {
                if(args.length() == 0)
                {
                    sender.sendMessage("The command is working!");
                    return true;
                }
            }
            sender.sendMessage("Returned False within code!");
            return false;
        }
    or try out:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            if(cmd.getName().equalsIgnoreCase("togglese"))
            {
                if(args.length() == 0)
                {
                    sender.sendMessage("The command is working!");
                    return true;
                }
            }
            sender.sendMessage("Returned False within code!");
            return false;
        }
     
  3. Offline

    Waterflames

    Try this one:
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    3. {
    4. if(cmd.getName().equalsIgnoreCase("togglese"))
    5. {
    6. sender.sendMessage("The command is working!");
    7. return true;
    8. }
    9. sender.sendMessage("Returned False within code!");
    10. return false;
    11. }
    12.  
     
  4. Offline

    Docithe

    Nope. Tried all of those suggestions and it still returns the Usage. =/
     
  5. Offline

    Docithe

    Still getting this error. any other suggestions?
     
  6. Offline

    nisovin

    Where is this block of code at? Your main plugin class, I assume?
     
  7. Offline

    katerk

    For the plugin.yml try this:
    HTML:
    name: BukkitHelp
    main: me.katerk.BukkitHelp.BukkitHelp
    version: 1.0
    author: katerk
    description: >
                  BukkitHelp v.1.0
    commands:
      info:
        description: Info
        usage: /<command>
      togglese:
        description: null
        usage: /<command> 
    in time i'll find a javacode for it
     
  8. Offline

    thehutch

    When you return false the usage is sent to the user who failed the command, although I recommend not removing it because it also has other useful properties, my suggestion would be to just remove the usage: from the plugin.yml altogether.
     
  9. I just removed the usage from Plugin.yml

    It seems to work.

    Keir
     
  10. Offline

    Docithe

    Removing the usage from the plugin.yml does not work for me. It simply returns nothing rather than "The command is working!".

    After slight tweaking of the plugin.yml file, however, I can now get it to return the command to me. For example, I type "/togglese", and it sends back "/togglese" in the text bar. I'm still unsure of what's causing this.
     
  11. Offline

    Ice_Sword

    Does this work? And if not, what does it do?


    Also, can you post the code that returns the result you've listed above?

    Code:java
    1.  
    2.  
    3. package forkicks;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7.  
    8.  
    9. public class Forkicks {
    10.  
    11. public static void main(String[] args) {
    12.  
    13. }
    14. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    15. {
    16.  
    17.  
    18. if(cmd.getName().equalsIgnoreCase("togglese"))
    19. {
    20. sender.sendMessage("The command is working!");
    21. return true;
    22. }
    23. else
    24. {
    25. sender.sendMessage("Returned False within code!");
    26. return false;
    27. }
    28.  
    29. }
    30.  
    31. }
    32.  


    And this is the YML that would go along with the above command:

    Code:
    name: Forkicks
    main: forkicks.Forkicks
    version: Awesome
    
    
    commands:
       togglese:
         description: Whatevs.
         usage: /<command>
    
     
  12. Offline

    katerk

    if(commandLabel.equalsIgnoreCase("command") ) {
    if(args.lenth==0){
    player.sendMessage(ChatColor.GREEN + "This command work");

    }


    you can do the command also like this
     
  13. class forkicks.Forkicks dont implements JavaPlugin error
     
  14. Offline

    Ice_Sword

    My bad, just add "extends JavaPlugin" after "public class Forkicks"
     
  15. Still fail, you need to specifi the methodes "onEnable()" and "onDisable()" because they are abstract at JavaPlugin
     
  16. Offline

    heisan213

    If you remove the cmd.getName().equalsIgnorecase(""){} you see that every time onCommand is called, return false will be the first (after the failed message) code to execute.
     
  17. Offline

    Ice_Sword

    Sorry, let me try this one more time.... If it still doesn't work tell me what error you get.



    Code:java
    1.  
    2.  
    3. package forkicks;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7.  
    8.  
    9. public class Forkicks extends JavaPlugin {
    10.  
    11. public static void main(String[] args) {
    12.  
    13. }
    14.  
    15. @Override
    16. public void onEnable()
    17. {
    18. PluginManager pm = this.getServer().getPluginManager();
    19. log.info("Plugin active!");
    20.  
    21. }
    22.  
    23. @Override
    24. public void onDisable()
    25. {
    26. log.info("Plugin disabled.");
    27. }
    28.  
    29. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    30. {
    31.  
    32.  
    33. if(cmd.getName().equalsIgnoreCase("togglese"))
    34. {
    35. sender.sendMessage("The command is working!");
    36. return true;
    37. }
    38. else
    39. {
    40. sender.sendMessage("Returned False within code!");
    41. return false;
    42. }
    43.  
    44. }
    45.  
    46. }
    47.  


    And this is the YML that would go along with the above command:

    Code:
    name: Forkicks
    main: forkicks.Forkicks
    version: Awesome
     
     
    commands:
      togglese:
        description: Whatevs.
        usage: /<command>
    
     
  18. class JavaPlugin not found, mayby add an import to it?
    EDIT: field log not declared
     
  19. Offline

    Ice_Sword

    Yes, add an import. And add this before the onEnable:
    static final Logger log = Logger.getLogger("Minecraft");


    Actually, make sure all of these are imported:

    import java.util.logging.Logger;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
Thread Status:
Not open for further replies.

Share This Page