crwdns150085:0crwdne150085:0

crwdns150087:0:javadoc:crwdne150087:0

crwdns150089:0:javadoc:crwdne150089:0

crwdns150091:0crwdne150091:0

crwdns150093:0crwdne150093: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");

crwdns150095:0crwdne150095:0

crwdns150097:0crwdne150097:0

crwdns150099:0crwdne150099:0

crwdns150101:0crwdne150101:0

crwdns150103:0crwdne150103:0

crwdns150105:0crwdne150105:0

crwdns150107:0crwdne150107:0

crwdns150109:0:doc:crwdne150109:0

crwdns150111:0crwdne150111:0

crwdns150113:0crwdne150113:0

crwdns150115:0crwdne150115:0

crwdns150117:0crwdne150117:0

crwdns150119:0crwdne150119:0

crwdns150121:0crwdne150121:0

crwdns150123:0crwdne150123:0

crwdns150125:0:doc:crwdne150125:0

crwdns150127:0crwdne150127:0

crwdns150129:0:doc:crwdne150129:0

crwdns150131:0crwdne150131:0

crwdns150133:0crwdne150133:0

crwdns150135:0crwdne150135:0

crwdns150137:0crwdne150137:0

crwdns150139:0crwdne150139:0

crwdns150141:0crwdne150141:0

crwdns150143:0crwdne150143:0

crwdns150145:0:javadoc:crwdnd150145:0:javadoc:crwdne150145:0

  • crwdns150147:0crwdne150147:0

  • crwdns150149:0:doc:crwdne150149:0

crwdns150151:0crwdne150151: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

crwdns150153:0:doc:crwdne150153:0

crwdns150155:0crwdne150155:0

crwdns150157:0crwdne150157:0

crwdns150159:0:javadoc:crwdne150159: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

crwdns150161:0[player]crwdnd150161:0[player]crwdne150161:0

crwdns150163:0:doc:crwdne150163:0

crwdns150165:0crwdne150165:0

crwdns150167:0:javadoc:crwdnd150167:0:javadoc:crwdnd150167:0:javadoc:crwdnd150167:0:javadoc:crwdne150167:0

crwdns150169:0crwdne150169:0

crwdns150171:0crwdne150171:0

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

crwdns150173:0crwdne150173:0

crwdns150175:0crwdne150175:0

crwdns150177:0:javadoc:crwdnd150177:0:javadoc:crwdne150177:0