crwdns156705:0crwdne156705:0

crwdns156707:0crwdne156707:0

crwdns156709:0:doc:crwdne156709:0

crwdns156711:0crwdne156711:0

crwdns156713:0crwdne156713:0

public class MyBroadcastCommand implements Command.Raw {

    private final Component usage = Component.text("<message>");
    private final Component description = Component.text("Display a message to all players");

    @Override
    public CommandResult process(CommandCause cause, ArgumentReader.Mutable arguments) throws CommandException {
        String message = arguments.remaining();
        Sponge.server().broadcastAudience().sendMessage(Component.text(message));
        return CommandResult.success();
    }

    @Override
    public List<CommandCompletion> complete(CommandCause cause, ArgumentReader.Mutable arguments) throws CommandException {
        return Collections.emptyList();
    }

    @Override
    public boolean canExecute(CommandCause cause) {
        return cause.hasPermission("myplugin.broadcast");
    }

    @Override
    public Optional<Component> shortDescription(CommandCause cause) {
        return Optional.of(this.description);
    }

    @Override
    public Optional<Component> extendedDescription(CommandCause cause) {
        return Optional.empty();
    }

    @Override
    public Component usage(CommandCause cause) {
        return this.usage;
    }
}

Tip

crwdns156715:0:javadoc:crwdne156715:0

crwdns156717:0crwdne156717:0

crwdns156719:0:javadoc:crwdnd156719:0:javadoc:crwdne156719:0

@Inject
PluginContainer container;

@Listener
public void onRegisterRawCommands(final RegisterCommandEvent<Command.Raw> event){
    event.register(this.container, new MyBroadcastCommand(), "broadcast");
}