Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Command system almost-complete rework #84

Open
wants to merge 107 commits into
base: master
Choose a base branch
from

Conversation

LichtHund
Copy link
Member

@LichtHund LichtHund commented Oct 10, 2022

Goals

  • Allow nested commands.
  • Arguments as sub commands.
  • Custom annotations.

To achieve the goals I have decided to completely revamp quite a few of the systems.
This also came with an in my opinion improved syntax.

Syntax change

The previous syntax was made to avoid confusion and differentiate between method and class annotations.
Now there are no more difference on the annotations so the change makes sense.
I also find that default wasn't very clear what it meant, so I'm hoping the change also makes it more clear what each method does.

Old

@Command("foo")
public class MyCommand extends BaseCommand {
    
    @Default
    public void defaultSub(Sender sender) {} // /foo
    
    @SubCommand("bar")
    public void barSub(Sender sender) {} // /foo bar
}

New

@Command("foo")
public class MyCommand {
    
    @Command
    public void defaultSub(Sender sender) {} // /foo
    
    @Command("bar")
    public void barSub(Sender sender) {} // /foo bar
}

Nested Commands

The syntax for nested command will be the following:

@Command("foo")
public class MyCommand {
    
    @Command
    public void defaultSub(Sender sender) {} // /foo
    
    @Command("bar")
    public void barSub(Sender sender) {} // /foo bar

    @Command("nested")
    class Nested {
    
        @Command
        public void defaultSub(Sender sender) {} // /foo nested
    
        @Command("bar")
        public void barSub(Sender sender) {} // /foo nested bar
    }
}

Arguments as sub commands

The syntax for having arguments as sub commands.

@Command("foo")
public class MyCommand {

    @Command
    class Nested {

        private final String argument;
       
        public Nested(String argument) {
            this.argument = argument; // Passing the argument to be used in the sub command.
        }
   
        @Command
        public void defaultSub(Sender sender) {} // /foo <argument>
    
        @Command("bar")
        public void barSub(Sender sender) {} // /foo <argument> bar
    }
}

Custom annotations

Allow users to create their own annotations and behaviors to be added to the commands.
This is currently not prototyped. Once it is I'll edit the PR.

@LichtHund LichtHund self-assigned this Oct 10, 2022
@LichtHund LichtHund added enhancement New feature or request WIP labels Oct 10, 2022
@LichtHund LichtHund added this to the Rewrite v2.0 milestone Oct 10, 2022
@bobooski
Copy link

This looks, respectfully, very sexy. I am a fan.

@Sparky983
Copy link
Contributor

Amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants