Skip to content

Custom CommandOperator's

ancap-kun edited this page Feb 17, 2023 · 1 revision

Thanks to the smart object-oriented design, CommandAPI is not limited to the proposed standard objects and methods. You can always write your own CommandOperator.

A CommandOperator is an object that takes in data about what the player enters and executes some custom logic based on that. Pretty much the same as the standard CommandExecutor from Bukkit. Here are two methods you can implement:

void on(CommandWrite write);
void on(CommandDispatch dispatch);

If you connect the CommandOperator directly to the command center or to some tree, these methods will be called and data will be passed there.

You can also use CommandOperator as a lambda expression in the command tree, like this:

``java new CommandDelegator( new Raw( new Adviser(new LAPIMessage(Artifex.class, "command.language.enter-language") ), new SubCommand( new StringDelegatePattern("set"), new Arguments( List.of( new Argument("language", new Self() ), // this is where the CommandOperator is hidden as a lambda. Dispatch is a CommandDispatch. dispatch -> Bukkit.getPluginManager().callEvent( new LanguageChangeEvent( dispatch.source().sender(), dispatch.arguments().get("language", String.class) ) ) ) ) )

Clone this wiki locally