crwdns120081:0crwdne120081:0
crwdns120083:0:javadoc:crwdnd120083:0:javadoc:crwdne120083:0
crwdns120085:0:doc:crwdne120085:0
crwdns120087:0crwdne120087:0
crwdns120089:0crwdne120089: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, @Nullable Location<World> targetPosition) throws CommandException {
return Collections.emptyList();
}
}
Tip
crwdns120091:0:javadoc:crwdne120091:0
crwdns120093:0crwdne120093:0
crwdns120095:0:javadoc:crwdnd120095:0:javadoc:crwdne120095:0
import org.spongepowered.api.command.CommandManager;
CommandManager cmdService = Sponge.getCommandManager();
PluginContainer plugin = ...;
cmdService.register(plugin, new MyBroadcastCommand(), "message", "broadcast");
Note
crwdns120097:0crwdne120097:0
crwdns120099:0crwdne120099:0
crwdns120101:0crwdne120101:0
crwdns120103:0:javadoc:crwdne120103:0
crwdns120105:0crwdne120105: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");