Best command system?

Discussion in 'Plugin Development' started by ImPhantom, May 14, 2014.

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


    So, I've always done my commands by making separate classes in a different package that all implement CommandExecutor. But i was recently looking at the essentials source because i had some time to kill... and i noticed that they do commands in a different way that is quite a bit cleaner than mine... I am making this post to get peoples opinions on what they think is the best/cleanest way to make commands... And please don't say "put them all in the main class" because that is not clean in any way.

    EDIT: Essentials Commands:
  2. Offline


    I personally use a set of classes: a "general" command executor, a "player" command executor, and a "console" command executor. General is both, and player/console extend it but provide an onCommand for each. They're all abstract classes, the onCommand is meant to be overridden. It's a stripped down version where you either pass the player or sender, the command's name, and the arguments. Player and Console are handled by different methods because I find it cleaner. The commands are registered by instantiating the classes, they register themselves. I simply provide them with a JavaPlugin instance, minimum rank to use, and a list of aliases. The Rank stuff is part of a custom rank system because I don't really like the permissions API and have no obligation to use it in this case. Trust me, it's simpler that way.

    Obviously, some of that only works because the code is completely proprietary, but I like it. I might make it more "generic" later, like registering it along with required arguments or something, but it works fine for now.

    Annotation-based command systems are also pretty cool, but they feel too decentralized to me.
  3. Offline


    It depends on how complicated your command structure is. I definitely prefer classes for a complex command handler, but as an alternative idea on simpler plugins using argument based commands, I use an enum based command handler that allows me to easily manage the number of arguments after the command argument and even return custom help text for each one.
  4. Offline


    I've heard people like to use "Skript." Never tried it myself, but apparently it's simplistic.
  5. Offline


    I've seen it, I can't see the point. They have effectively created a new programming language as a front end to Java & Bukkit so that users don't have to learn Java but they still have to learn that programming language. Why not just learn Java?
  6. Offline


  7. Offline


    I can't exactly say which is the 'best' command structure, as that is slightly objective (What are we defining as best? fastest, easiest to read, quickest to write? Most of what we would use to define best would be slightly subjective).

    I can totally say that putting them in the main class is probably one of the worst ways to do commands in my opinion. But I won't go into that for now.

    Personally, what I do is simply have a package for my commands, and register each command in a separate command executor. I don't any fancy annotation or special class system for my commands.

    Below is an example of what my main and one of my command class looks like. As you can see, it is simple to add more commands, it is tidy (in my opinion anyway) (subroutines are always tidy). This is also how I tend to handle subcommands as well, especially if I know I am going to have a lot of them.
Thread Status:
Not open for further replies.

Share This Page