crwdns150005:0crwdne150005:0

crwdns150007:0:javadoc:crwdnd150007:0:javadoc:crwdne150007:0

crwdns150009:0:doc:crwdne150009:0

crwdns150011:0crwdne150011:0

crwdns150013:0crwdne150013:0

import org.spongepowered.api.Sponge;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

public class MyBroadcastCommand implements CommandCallable {

    private final Optional<Text> desc = Optional.of(Text.of("Displays a message to all players"));
    private final Optional<Text> help = Optional.of(Text.of("Displays a message to all players. It has no color support!"));
    private final Text usage = Text.of("<message>");

    public CommandResult process(CommandSource source, String arguments) throws CommandException {
        Sponge.getServer().getBroadcastChannel().send(Text.of(arguments));
        return CommandResult.success();
    }

    public boolean testPermission(CommandSource source) {
        return source.hasPermission("myplugin.broadcast");
    }

    public Optional<Text> getShortDescription(CommandSource source) {
        return desc;
    }

    public Optional<Text> getHelp(CommandSource source) {
        return help;
    }

    public Text getUsage(CommandSource source) {
        return usage;
    }

    public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
        return Collections.emptyList();
    }
}

Tip

crwdns150015:0:javadoc:crwdne150015:0

crwdns150017:0crwdne150017:0

crwdns150019:0:javadoc:crwdnd150019:0:javadoc:crwdne150019:0

import org.spongepowered.api.command.CommandManager;

CommandManager cmdService = Sponge.getCommandManager();
cmdService.register(plugin, new MyBroadcastCommand(), "message", "broadcast");

Note

crwdns150021:0crwdne150021:0

crwdns150023:0crwdne150023:0

crwdns150025:0crwdne150025:0

crwdns150027:0:javadoc:crwdne150027:0

crwdns150029:0crwdne150029:0

import org.spongepowered.api.command.dispatcher.SimpleDispatcher;

CommandCallable subCommand1 = ...;
CommandCallable subCommand2 = ...;

SimpleDispatcher rootCommand = new SimpleDispatcher();

rootCommand.register(subCommand1, "subcommand1", "sub1");
rootCommand.register(subCommand2, "subcommand2", "sub2");

Sponge.getCommandManager().register(this, rootCommand, "root");