Command only returns the usage

Discussion in 'Spigot Plugin Development' started by matthijspc, Jun 26, 2016.

  1. Hello,
    I wanted to add a little command which returns a small message.
    I've written this:
    Code (Text):

    public class Main extends JavaPlugin {

        public boolean onCommand(CommandSender sender, Command cmd, String commandlabel){
            if(cmd.getName().equalsIgnoreCase("test")) {
                sender.sendMessage("test succesful");
            }
            return true;
        }
     
    And added this to the plugin.yml:
    Code (Text):

    name: Test
    version: 1.0
    main: me.matthijspc.test.Main
    author: Matthijs van de Kuilen
    prefix: Test
    description: This plugin add recipes for uncraftable items.
    commands:
     test:
      description: Test command
      usage: /<command>
     
    If I runs the command the server returns "/test".
    What did I wrong?

    Thank in advance
    (sorry for bad english)
     
  2. Your class doesn't implement CommandExecutor, so it doesn't know it's a command and when to call the method.
     
  3. Use
    • public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    instead of what you're using.
     
    • Agree Agree x 1
  4. @GamerzKing you dont have to implement command executor in your main class. At least that's what I thought
     
  5. It's not necessary if the onCommand method is in the Main class. Pretty sure it won't change the outcome :p
     
    • Agree Agree x 1
  6. Oh, that's right :p Forgot JavaPlugin implements it by default. My bad!
     
    • Friendly Friendly x 1
  7. Remove the usage from the plugin.yml. I'm pretty sure that will fix it :)
     
  8. @GamerzKing ya he needs to change that and
     
    • Agree Agree x 1
  9. @gustavwww correct me if I'm wrong but I dont think that is necessary, I think it's just the excepted method, but yes I would recommend him add that even if it's not essential :)
     
    • Agree Agree x 2
  10. Wouldn't affect anything. It's usually recommended so you can tell that the method is overridden, but it's not essential. And in this case, it's not overridden, since the parameters are wrong anyways :p
     
    • Agree Agree x 1