use of org.spongepowered.api.command.args.ChildCommandElementExecutor 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.args.ChildCommandElementExecutor 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();
}
use of org.spongepowered.api.command.args.ChildCommandElementExecutor in project SpongeCommon by SpongePowered.
the class SpongeCommandFactory method createSpongeCommand.
/**
* Create a new instance of the Sponge command structure.
*
* @return The newly created command
*/
public static CommandSpec createSpongeCommand() {
final ChildCommandElementExecutor flagChildren = new ChildCommandElementExecutor(null);
final ChildCommandElementExecutor nonFlagChildren = new ChildCommandElementExecutor(flagChildren);
nonFlagChildren.register(createSpongeVersionCommand(), "version");
nonFlagChildren.register(createSpongeBlockInfoCommand(), "blockInfo");
nonFlagChildren.register(createSpongeEntityInfoCommand(), "entityInfo");
nonFlagChildren.register(createSpongeAuditCommand(), "audit");
nonFlagChildren.register(createSpongeHeapCommand(), "heap");
nonFlagChildren.register(createSpongePluginsCommand(), "plugins");
nonFlagChildren.register(createSpongeTimingsCommand(), "timings");
nonFlagChildren.register(createSpongeWhichCommand(), "which");
flagChildren.register(createSpongeChunksCommand(), "chunks");
flagChildren.register(createSpongeConfigCommand(), "config");
// TODO: Should these two be subcommands of config, and what is now config be set?
flagChildren.register(createSpongeReloadCommand(), "reload");
flagChildren.register(createSpongeSaveCommand(), "save");
flagChildren.register(createSpongeTpsCommand(), "tps");
SpongeImplHooks.registerAdditionalCommands(flagChildren, nonFlagChildren);
return CommandSpec.builder().description(Text.of("General Sponge command")).extendedDescription(// TODO: Automatically generate from child executors (wait for help system on this)
Text.of(// TODO: Automatically generate from child executors (wait for help system on this)
"commands:\n", INDENT, title("chunks"), LONG_INDENT, "Prints chunk data for a specific dimension or world(s)\n", INDENT, title("conf"), LONG_INDENT, "Configure sponge settings\n", INDENT, title("heap"), LONG_INDENT, "Dump live JVM heap\n", INDENT, title("reload"), LONG_INDENT, "Reloads a global, dimension, or world config\n", INDENT, title("save"), LONG_INDENT, "Saves a global, dimension, or world config\n", INDENT, title("version"), LONG_INDENT, "Prints current Sponge version\n", INDENT, title("audit"), LONG_INDENT, "Audit mixin classes for implementation\n", INDENT, title("plugins"), LONG_INDENT, "List currently installed plugins\n", INDENT, title("which"), LONG_INDENT, "List plugins that own a specific command\n", INDENT, title("tps"), LONG_INDENT, "Provides TPS (ticks per second) data for loaded worlds\n", SpongeImplHooks.getAdditionalCommandDescriptions())).arguments(firstParsing(nonFlagChildren, flags().flag("-global", "g").valueFlag(world(Text.of("world")), "-world", "w").valueFlag(dimension(Text.of("dimension")), "-dimension", "d").buildWith(flagChildren))).executor(nonFlagChildren).build();
}
use of org.spongepowered.api.command.args.ChildCommandElementExecutor in project SpongeCommon by SpongePowered.
the class ScaledHealthTest method getHealthCommand.
private static CommandCallable getHealthCommand() {
final ChildCommandElementExecutor flagChildren = new ChildCommandElementExecutor(null);
final ChildCommandElementExecutor nonFlagChildren = new ChildCommandElementExecutor(flagChildren);
nonFlagChildren.register(getShowHealth(), "show");
nonFlagChildren.register(getSetHealthScale(), "setScale");
nonFlagChildren.register(getSetHealth(), "setHealth");
nonFlagChildren.register(getSetMaxHealth(), "setMax");
return CommandSpec.builder().description(Text.of("ScaledHealth command")).extendedDescription(Text.of("commands:\n", "set a trail to you as a player")).arguments(firstParsing(nonFlagChildren)).executor(nonFlagChildren).build();
}
Aggregations