Skip to content

Hey there! If you like my work, you can support me by sponsoring me on GitHub. Thanks! ❤

Sponsor me
on GitHub

@Command & @Executor

To define basic structure of a command and subcommands, use the @Command and @Executor annotations.

Command

You can declare a simple command. For example, /hello:

java
@Command(name = "hello")
public class HelloCommand {
    @Executor
    void execute() {
        // /hello
    }
}

Subcommands

It is also easy to create a command with subcommands. For example, /time set <time>, where time is an integer, and subcommands /time set day and /time set night:

java
@Command(name = "time set")
public class TimeSetCommand {
    @Executor
    void execute(@Arg int time) {
        // /time set <time>
    }

    @Executor(name = "day")
    void day() {
        // /time set day
    }

    @Executor(name = "night")
    void night() {
        // /time set night
    }
}

INFO

To read more about the @Arg annotation, visit the Arguments section.

Also you can create a command with subcommands in a different way. For example, /time add <time>, /time set <time>, and /time set day:

java
@Command(name = "time")
public class TimeCommand {
    @Executor(name = "add")
    void addTime(@Arg int time) {
        // /time add
    }

    @Executor(name = "set")
    void setTime(@Arg int time) {
        // /time set
    }

    @Executor(name = "set day")
    void setDay() {
        // /time set day
    }
}

Once you have defined your commands, you can register them in the LiteCommands builder:

java
// LiteCommands builder
.commands(
    new HelloCommand(),
    new TimeSetCommand()
)
.build();

Made by LiteDevelopers and Contributors with ❤️