use of org.spongepowered.api.command.spec.CommandExecutor in project SpongeCommon by SpongePowered.
the class SpongePaginationService method buildPaginationCommand.
private CommandSpec buildPaginationCommand() {
final ActivePaginationCommandElement paginationElement = new ActivePaginationCommandElement(t("pagination-id"));
CommandSpec next = CommandSpec.builder().description(t("Go to the next page")).executor((src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().nextPage();
return CommandResult.success();
}).build();
CommandSpec prev = CommandSpec.builder().description(t("Go to the previous page")).executor((src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().previousPage();
return CommandResult.success();
}).build();
CommandElement pageArgs = integer(t("page"));
CommandExecutor pageExecutor = (src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().specificPage(args.<Integer>getOne("page").get());
return CommandResult.success();
};
CommandSpec page = CommandSpec.builder().description(t("Go to a specific page")).arguments(pageArgs).executor(pageExecutor).build();
// Fallback to page arguments
ChildCommandElementExecutor childDispatcher = new ChildCommandElementExecutor(pageExecutor);
childDispatcher.register(next, "next", "n");
childDispatcher.register(prev, "prev", "p", "previous");
childDispatcher.register(page, "page");
// https://github.com/SpongePowered/SpongeAPI/issues/1272
return CommandSpec.builder().arguments(paginationElement, firstParsing(childDispatcher, pageArgs)).executor(childDispatcher).description(t("Helper command for paginations occurring")).build();
}
use of org.spongepowered.api.command.spec.CommandExecutor in project LanternServer by LanternPowered.
the class LanternPaginationService method buildPaginationCommand.
@SuppressWarnings("ConstantConditions")
private CommandSpec buildPaginationCommand() {
// TODO Completely redo this once command refactor is out and PR changes to Sponge as well
final ActivePaginationCommandElement paginationElement = new ActivePaginationCommandElement(t("pagination-id"));
CommandSpec next = CommandSpec.builder().description(t("Go to the next page")).executor((src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().nextPage();
return CommandResult.success();
}).build();
CommandSpec prev = CommandSpec.builder().description(t("Go to the previous page")).executor((src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().previousPage();
return CommandResult.success();
}).build();
CommandElement pageArgs = integer(t("page"));
CommandExecutor pageExecutor = (src, args) -> {
args.<ActivePagination>getOne("pagination-id").get().specificPage(args.<Integer>getOne("page").get());
return CommandResult.success();
};
CommandSpec page = CommandSpec.builder().description(t("Go to a specific page")).arguments(pageArgs).executor(pageExecutor).build();
// Fallback to page arguments
ChildCommandElementExecutor childDispatcher = new ChildCommandElementExecutor(pageExecutor);
childDispatcher.register(next, "next", "n");
childDispatcher.register(prev, "prev", "p", "previous");
childDispatcher.register(page, "page");
// https://github.com/SpongePowered/SpongeAPI/issues/1272
return CommandSpec.builder().arguments(paginationElement, firstParsing(childDispatcher, pageArgs)).executor(childDispatcher).description(t("Helper command for paginations occurring")).build();
}
Aggregations