crwdns130821:0crwdne130821:0

crwdns130823:0:javadoc:crwdne130823:0

crwdns130825:0:javadoc:crwdne130825:0

crwdns130827:0crwdne130827:0

crwdns130829:0crwdne130829:0

import org.spongepowered.api.Sponge;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.command.spec.CommandSpec;

CommandSpec myCommandSpec = CommandSpec.builder()
    .description(Text.of("Hello World Command"))
    .permission("myplugin.command.helloworld")
    .executor(new HelloWorldCommand())
    .build();

Sponge.getCommandManager().register(plugin, myCommandSpec, "helloworld", "hello", "test");

crwdns130831:0crwdne130831:0

crwdns130833:0crwdne130833:0

crwdns130835:0crwdne130835:0

crwdns130837:0crwdne130837:0

crwdns130839:0crwdne130839:0

crwdns130841:0crwdne130841:0

crwdns130843:0crwdne130843:0

crwdns130845:0:doc:crwdne130845:0

crwdns130847:0crwdne130847:0

crwdns130849:0crwdne130849:0

crwdns130851:0crwdne130851:0

crwdns130853:0crwdne130853:0

crwdns130855:0crwdne130855:0

crwdns130857:0crwdne130857:0

crwdns130859:0crwdne130859:0

crwdns130861:0:doc:crwdne130861:0

crwdns130863:0crwdne130863:0

crwdns130865:0:doc:crwdne130865:0

crwdns130867:0crwdne130867:0

crwdns130869:0crwdne130869:0

crwdns130871:0crwdne130871:0

crwdns130873:0crwdne130873:0

crwdns130875:0crwdne130875:0

crwdns130877:0crwdne130877:0

crwdns130879:0crwdne130879:0

crwdns130881:0:javadoc:crwdnd130881:0:javadoc:crwdne130881:0

  • crwdns130883:0crwdne130883:0

  • crwdns130885:0:doc:crwdne130885:0

crwdns130887:0crwdne130887:0

import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;

public class HelloWorldCommand implements CommandExecutor {

    @Override
    public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
        src.sendMessage(Text.of("Hello World!"));
        return CommandResult.success();
    }
}

Tip

crwdns130889:0:doc:crwdne130889:0

crwdns130891:0crwdne130891:0

crwdns130893:0crwdne130893:0

crwdns130895:0:javadoc:crwdne130895:0

import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.command.source.CommandBlockSource;
import org.spongepowered.api.command.source.ConsoleSource;

if(src instanceof Player) {
    Player player = (Player) src;
    player.sendMessage(Text.of("Hello " + player.getName() + "!"));
}
else if(src instanceof ConsoleSource) {
    src.sendMessage(Text.of("Hello GLaDOS!"));
    // The Cake Is a Lie
}
else if(src instanceof CommandBlockSource) {
    src.sendMessage(Text.of("Hello Companion Cube!"));
    // <3
}

Note

crwdns130897:0[player]crwdnd130897:0[player]crwdne130897:0

crwdns130899:0:doc:crwdne130899:0

crwdns130901:0crwdne130901:0

crwdns130903:0:javadoc:crwdnd130903:0:javadoc:crwdnd130903:0:javadoc:crwdnd130903:0:javadoc:crwdne130903:0

crwdns130905:0crwdne130905:0

crwdns130907:0crwdne130907:0

CommandResult result = CommandResult.builder()
    .affectedEntities(42)
    .successCount(1)
    .build();

crwdns130909:0crwdne130909:0

crwdns130911:0crwdne130911:0

crwdns130913:0:javadoc:crwdnd130913:0:javadoc:crwdne130913:0