1.17.x Command Framework ideas

Discussion in 'Spigot Plugin Development' started by Korwin, Jun 29, 2021.

  1. Hi guys i am making right now Command Framework for making life a lot easier with organizing commands what would you want in command frameworks that you really want to have and use for now:
    I have idea several good ideas on how to reduce a lot of boilerplate by just simply coding and not doing anything beside it for example describing command etc
     
  2. This might sound like an impossible task but would be amazing to have.
    Something like a MVC framework within minecraft where you can indicate every command/subcommand by just using annotations in combination with reflection. Using reflection to store and invoke methods and pass the Request variable along.

    for instance the command
    Code (Text):
    /myplugin settings autoupdate {type}
    or
    Code (Text):
    /myplugin settings player {playername} set/get......
    Code (Java):

    @Command("settings")
    class SettingCommand extends Command {


        @subcommand(name="autoupdate", params=@param(name="type", type=boolean.class))
        public void autoupdate(Request request) {
            Player player = request.getPlayer();
            boolean type = request.getParam("type");
            request.error("something went wrong");
        }
     

        @subcommand(name="player", child=SettingCommand.PlayerCommand.class, params=@param(name="playername", type=String.class))
        public void player(Request request) {
            Player player = request.getPlayer();
        }
     
        class PlayerCommand extends ChildCommand {
         @subcommand......
         public void set(Request request) {}
        }
    }
     
     
    • Creative Creative x 1
  3. I was thinking of getting rid completely of annotations and make them optional everything would be based around code you write something like the C# ASP.NET controllers you add annotations when you need to otherwise it defaults to basic code you wrote and for example when you have function with parameters


    Code (Java):
    class BaseCommand {
       public void setSomething(CommandSender sender,Player player,int argument1){
       
       }
    }
    You would basically done that and boom all you need to do is to init it by calling command
    /base setsomething <player> <argument>

    Thinking also about messaging player with return value i saw too much empty return values lmao

    But also i would probably take that into consideration thank you :D probably in later stages but still gonna have it on my mind
     
    • Creative Creative x 1
  4. At first, I was thinking of the same thing but then I realized that it would be very challenging to make subcommands with abstraction such as
    Code (Text):
    /base get {playername} set {permission} value {bool}
    The only way to to do that is by defining all the possible paths in the beginning but still....
     
    • Useful Useful x 1
  5. I got an idea on how to do that also you would basically have the instance passed to the subcommand containing knowledge of the previous command it probably could get messy but i really don't have any idea besides that how it could be done
    Something like that:

    Code (Java):
    public class BaseCommand {
        public CommandDirector get(Player player){
            return new CommandDirector("set")
        }
        public CommandDirector set(CommandDirector commandDirector,String permission){
            Player player = (Player)commandDirector.get("get_player");
            return new CommandDirector("value");
        }
        public void value(CommandDirector commandDirector, boolean value){
            Player player = (Player)commandDirector.get("get::player");
            String permission = (String)commandDirector.get("set::player");
        }
    }
    That's a lot of code that you probably wouldn't need to write i want to simplify that
     
  6. idk why but i simply do not like annotions as a method for creating commands
     
  7. I don't like generally any code you write that is described when you write that code
     
  8. I don't see why annotations are such a bad thing. How else can you provide enough information for the command framework to know the: Permissions, Command Usage, Variable types.
    If you instead write this stuff all down in the methods, it will make the code unnecessary messy and not maintainable.
    Since a framework is made for scenarios like this. But of course, you have reflection. But would you spend so much time in making complex reflection code to achieve something that is easily done by using simple annotations.
     
  9. I haven't really FULLY tried annotations. i believe i tried once making a simple command tho.
    Personally not for me ig, i dont see anything bad in them but id much rather have like an abstract command class that i just extend
     
  10. I mean you have everything basically in the method already you're just probably repeating yourself and when you need to change something you need to change several things