-
Notifications
You must be signed in to change notification settings - Fork 2
创建并使用
defoli_ation edited this page Oct 24, 2019
·
3 revisions
SimpleCommandManager commandManager = new SimpleCommandManager();
SimpleCommand simpleCommand = new SimpleCommand("command");
simpleCommand.setExecutor((sender, command, args1) -> System.out.println("a simple command case"));
commandManager.register(simpleCommand);
commandManager.execute(sender,"command");
如此一个最简单的命令执行器就完成了,这里面需要的东西很多,但你可以通过我们的wiki慢慢了解整个系统
首先先写一个类负责处理命令并使用 @Command 标记方法
public class CommandHandler{
@Command("say")
public void say(String message){
System.out.println(message);
}
}
然后将命令注册进SimpleCommandManager,但这里为了安全,我们将其封装了
MethodAnnotationCommand.getBuilder(commandManager)
.addHandler(new CommandHandler())
.register();
执行以上命令,注册就完成了,然后通过execute执行
commandManager.execute(sender,"say "a simple command case"");
仍未完善,以后补完