crwdns130741:0crwdne130741:0

crwdns130743:0:javadoc:crwdnd130743:0:javadoc:crwdne130743:0

crwdns130745:0:doc:crwdne130745:0

crwdns130747:0crwdne130747:0

crwdns130749:0crwdne130749: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

crwdns130751:0:javadoc:crwdne130751:0

crwdns130753:0crwdne130753:0

crwdns130755:0:javadoc:crwdnd130755:0:javadoc:crwdne130755:0

import org.spongepowered.api.command.CommandManager;

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

Note

crwdns130757:0crwdne130757:0

crwdns130759:0crwdne130759:0

crwdns130761:0crwdne130761:0

crwdns130763:0:javadoc:crwdne130763:0

crwdns130765:0crwdne130765: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");