use of org.spongepowered.api.command.CommandExecutor in project SpongeCommon by SpongePowered.
the class SpongePaginationService method createPaginationCommand.
public Command.Parameterized createPaginationCommand() {
final Parameter.Value<ActivePagination> paginationIdParameter = Parameter.builder(ActivePagination.class).addParser(new ActivePaginationParameter()).key("pagination-id").build();
final Command.Parameterized next = Command.builder().shortDescription(Component.text("Go to the next page")).executor((context) -> {
context.requireOne(paginationIdParameter).nextPage();
return CommandResult.success();
}).build();
final Command.Parameterized prev = Command.builder().shortDescription(Component.text("Go to the previous page")).executor((context) -> {
context.requireOne(paginationIdParameter).previousPage();
return CommandResult.success();
}).build();
final Parameter.Value<Integer> pageParameter = Parameter.integerNumber().key("page").build();
final CommandExecutor pageExecutor = (context) -> {
context.requireOne(paginationIdParameter).specificPage(context.requireOne(pageParameter));
return CommandResult.success();
};
final Command.Parameterized page = Command.builder().shortDescription(Component.text("Go to a specific page")).addParameter(pageParameter).executor(pageExecutor).build();
return Command.builder().addParameters(paginationIdParameter, Parameter.firstOf(pageParameter, Parameter.subcommand(next, "next", "n"), Parameter.subcommand(prev, "prev", "p", "previous"), Parameter.subcommand(page, "page"))).addChild(page, "page").shortDescription(Component.text("Helper command for paginations occurring")).executor(pageExecutor).build();
}
Aggregations