org.spongepowered.api.command.CommandCallable Java Examples

The following examples show how to use org.spongepowered.api.command.CommandCallable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrismCommands.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Build a complete command hierarchy
 * @return
 */
public static CommandSpec getCommand() {
    // Build child commands
    ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder();
    builder.put(ImmutableList.of("i", "wand"), InspectCommand.getCommand());
    builder.put(ImmutableList.of("l", "lookup"), LookupCommand.getCommand());
    builder.put(ImmutableList.of("near"), NearCommand.getCommand());
    // Sort order newest first for rollback, and oldest first for restore.
    builder.put(ImmutableList.of("rb", "rollback"), ApplierCommand.getCommand(Sort.NEWEST_FIRST));
    builder.put(ImmutableList.of("rs", "restore"), ApplierCommand.getCommand(Sort.OLDEST_FIRST));
    builder.put(ImmutableList.of("undo"), UndoCommand.getCommand());
    builder.put(ImmutableList.of("ext"), ExtinguishCommand.getCommand());
    builder.put(ImmutableList.of("?", "help"), HelpCommand.getCommand());

    return CommandSpec.builder()
        .executor((source, args) -> {
            // Check permission here, so the node doesn't apply to all child commands
            if (source.hasPermission("prism.info")) {
                source.sendMessage(Text.of(
                        Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi", TextColors.GRAY, ".\n"),
                        TextColors.DARK_AQUA, "Tracking so good the NSA stole our name.\n",
                        TextColors.GRAY, "Help: ", TextColors.WHITE, "/pr ?\n",
                        TextColors.GRAY, "IRC: ", TextColors.WHITE, "irc.esper.net #prism\n",
                        TextColors.GRAY, "Site: ", Format.url(Reference.WEBSITE), "\n",
                        TextColors.GRAY, "Source: ", Format.url(Reference.SOURCE)
                ));

                return CommandResult.success();
            } else {
                throw new CommandException(Format.error("You do not have permission to use this command."));
            }
        })
        .children(builder.build()).build();
}
 
Example #2
Source File: LibConfig.java    From ChatUI with MIT License 4 votes vote down vote up
public static CommandCallable createCommand() {
    return CommandSpec.builder()
            .child(CommandSpec.builder()
                    .arguments(GenericArguments.integer(Text.of("width")))
                    .executor((src, args) -> {
                        updatePlayer(config(src).withWidth(args.<Integer>getOne("width").get()), src);
                        saveConfig();
                        src.sendMessage(Text.of("Width setting changed"));
                        return CommandResult.success();
                    })
                    .build(), "width")
            .child(CommandSpec.builder()
                    .arguments(GenericArguments.integer(Text.of("height")))
                    .executor((src, args) -> {
                        updatePlayer(config(src).withHeight(args.<Integer>getOne("height").get()), src);
                        saveConfig();
                        src.sendMessage(Text.of("Height setting changed"));
                        return CommandResult.success();
                    })
                    .build(), "height")
            .child(CommandSpec.builder()
                    .arguments(GenericArguments.bool(Text.of("unicode")))
                    .executor((src, args) -> {
                        updatePlayer(config(src).withUnicode(args.<Boolean>getOne("unicode").get()), src);
                        saveConfig();
                        src.sendMessage(Text.of("Force Unicode setting changed"));
                        return CommandResult.success();
                    })
                    .build(), "unicode")
            .child(CommandSpec.builder()
                    .arguments(GenericArguments.optional(GenericArguments.string(Text.of("font data"))))
                    .executor((src, args) -> {
                        updatePlayer(config(src).withFontData(args.<String>getOne("font data").orElse(null)), src);
                        saveConfig();
                        src.sendMessage(Text.of("Font Data setting changed"));
                        return CommandResult.success();
                    }).build(), "font")
            .executor((src, args) -> {
                PlayerSettings settings = config(src);
                src.sendMessages(Text.of("Settings:"),
                        Text.of("Width: " + settings.getWidth()),
                        Text.of("Height: " + settings.getHeight()),
                        Text.of("Force Unicode: " + settings.getForceUnicode()),
                        Text.of("Font data: " + (settings.getFontData() == null ? "vanilla" : "custom")));
                return CommandResult.success();
            })
            .build();
}
 
Example #3
Source File: LowCommand.java    From UltimateCore with MIT License 4 votes vote down vote up
default CommandCallable getCallable() {
    return new LowCommandCallable(this);
}
 
Example #4
Source File: CommandExecutorBase.java    From EssentialCmds with MIT License 2 votes vote down vote up
/**
 * Creates a {@link CommandSpec} compatible version of the child commands from {@link CommandExecutorBase} objects.
 *
 * @param commands The commands to add to the map.
 * @return The object to add to the {@link org.spongepowered.api.command.spec.CommandSpec.Builder#children(Map)} method.
 */
protected final Map<List<String>, CommandCallable> getChildrenList(CommandExecutorBase... commands) {
    Preconditions.checkArgument(commands.length > 0, "There needs to be at least one CommandExecutorBase");
    return Arrays.asList(commands).stream().collect(Collectors.toMap(a -> Arrays.asList(a.getAliases()), CommandExecutorBase::getSpec));
}
 
Example #5
Source File: Command.java    From UltimateCore with MIT License votes vote down vote up
CommandCallable getCallable();