onCommand in another Class?

Discussion in 'Spigot Plugin Development' started by Nordiii, Jun 21, 2015.

  1. Hello, my question is if it is possible to create an extra class only for commands?

    I found this
    Code (Text):
    this.getCommand("test").setExecutor(new Commands());
    but this throws me an error and doesn`t look like it would do what I want.

    Would be nice if someone could help me! :)

    Sincerely Nordiii
  2. Make sure the Commands class extends the abstract class CommandExecutor
    • Like Like x 1
  3. I think you mean implements not extends or? because with extends my Commands class has to be a interface?
    I allready implement CommandExecutor :)
    With extend I wouldn`t know how I get this to work
  4. konsolas


    Yes, your Commands class needs to implement CommandExecutor.

    The command "test" must be defined in your plugin.yml, or it will throw a NullPointerException when run.
    • Like Like x 1
  5. Hmpf had a typo when i tested it, but how can I export every command into one class not only one? :(
  6. Create different classes implementing CommandExecutor:
    Code (Text):
    getCommand("test1").setExecutor(new Command1());
    getCommand("test2").setExecutor(new Command2());
    getCommand("test3").setExecutor(new Command3());
    and so on.
    • Like Like x 1
  7. Well it isn`t beautifull for like 6 commands so I wanted to register one executor which handels every input like when i use onCommand in my main Class :/

    But thanks for every replay ! :)