Subcommands in separate classes

Discussion in 'Spigot Plugin Development' started by loidsemus, Jun 7, 2017.

  1. I already have all my commands in separate classes, but when one command has a lot of subcommands it gets messy and hard to read, what's the best way, if possible, to have them (at least some) in separate classes? Is this even a good method to clean things up?

    I've also seen some ways to use annotations for commands, is this cleaner and/or better than the normal way?
  2. Annotation driven commands are not included in Bukkit, they have their own framework.

    There are many available for download.
  3. I know, that's what I was talking about, but are they better than using the normal way?
    • Optimistic Optimistic x 1
  4. I'd say have a single CommandExecutor (the one that has subcommands) and create a new abstract class SubCommand.
    Then have a list of SubCommands stored in the command executor & have it decide what subcommand to run.

    If those subcommands have subcommands, you can then just copy the original executor and convert it into just another subcommand, with more subcommands.
  5. They are more productive when creating big plugins with a lot of sub commands. But I don't know if I'd do annotation based. Look at Factions source code and see how they do it, it's very elegant and works smoothly