crwdns156721:0crwdne156721:0

crwdns156723:0:javadoc:crwdne156723:0

crwdns156725:0:javadoc:crwdne156725:0

crwdns156727:0crwdne156727:0

import org.spongepowered.api.command.Command;

public Command.Parameterized buildCommand(){
    return Command
        .builder()
        .executor(new HelloWorldCommand())
        .permission("myplugin.command.helloWorld")
        .shortDescription(Component.text("Hello World Command"))
        .build();
}

crwdns156729:0crwdne156729:0

crwdns156731:0crwdne156731:0

crwdns156733:0crwdne156733:0

crwdns156735:0crwdne156735:0

crwdns156737:0crwdne156737:0

crwdns156739:0crwdne156739:0

crwdns156741:0crwdne156741:0

crwdns156743:0crwdne156743:0

crwdns156745:0crwdne156745:0

crwdns156747:0crwdne156747:0

crwdns156749:0crwdne156749:0

crwdns156751:0crwdne156751:0

crwdns156753:0crwdne156753:0

crwdns156755:0crwdne156755:0

crwdns156757:0crwdne156757:0

crwdns156759:0crwdne156759:0

crwdns156761:0crwdne156761:0

crwdns156763:0crwdne156763:0

crwdns156765:0crwdne156765:0

crwdns156767:0crwdne156767:0

crwdns156769:0crwdne156769:0

crwdns156771:0crwdne156771:0

crwdns156773:0crwdne156773:0

crwdns156775:0crwdne156775:0

crwdns156777:0crwdne156777:0

public Command.Parameterized buildCommand(){
    return Command
        .builder()
        .executor(new HelloWorldCommand())
        .permission("myplugin.command.helloWorld")
        .shortDescription(Component.text("Hello World Command"))
        .executionRequirements(context -> context.cause().root() instanceof ServerPlayer)
        .build();
}

Note

crwdns156779:0[player]crwdnd156779:0[player]crwdne156779:0

crwdns156781:0:doc:crwdne156781:0

Tip

crwdns156887:0:javadoc:crwdne156887:0

crwdns156785:0crwdne156785:0

crwdns156787:0crwdne156787:0

crwdns156789:0:javadoc:crwdnd156789:0:javadoc:crwdne156789:0

crwdns156791:0crwdne156791:0

import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.parameter.CommandContext;
import org.spongepowered.api.command.CommandExecutor;
import org.spongepowered.api.command.exception.CommandException;

public class HelloWorldCommand implements CommandExecutor {

    @Override
    public CommandResult execute(CommandContext context) throws CommandException{
        context.sendMessage(Component.text("Hello World!"));
        return CommandResult.success();
    }

}

Tip

crwdns156793:0:doc:crwdne156793:0

crwdns156795:0crwdne156795:0

crwdns156797:0:javadoc:crwdne156797:0

crwdns156799:0:javadoc:crwdnd156799:0:javadoc:crwdne156799:0

crwdns156801:0crwdne156801:0

CommandResult result = CommandResult.builder()
    .result(0)
    .error(Component.text("Hello world in error form"))
    .build();

crwdns156803:0crwdne156803:0

crwdns156805:0crwdne156805:0

crwdns156733:0crwdne156733:0

crwdns156807:0crwdne156807:0

crwdns156809:0crwdne156809:0

crwdns156811:0crwdne156811:0

crwdns156813:0crwdne156813:0

crwdns156815:0crwdne156815:0

crwdns156817:0crwdne156817:0

crwdns156819:0crwdne156819:0

crwdns156821:0:javadoc:crwdnd156821:0:javadoc:crwdne156821:0

crwdns156823:0crwdne156823:0

crwdns156825:0:javadoc:crwdnd156825:0:javadoc:crwdne156825:0

crwdns156889:0:doc:crwdne156889:0

@Inject
PluginContainer container;

@Listener
public void onRegisterCommands(final RegisterCommandEvent<Command.Parameterized> event){
  event.register(this.container, buildCommand(), "helloworld", "hello", "test");
}

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