crwdns120173:0crwdne120173:0
crwdns120175:0:javadoc:crwdne120175:0
crwdns120177:0:javadoc:crwdne120177:0
crwdns120179:0crwdne120179:0
crwdns120181:0crwdne120181:0
import org.spongepowered.api.Sponge;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.command.spec.CommandSpec;
PluginContainer plugin = ...;
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");
crwdns120183:0crwdne120183:0
crwdns120185:0crwdne120185:0 |
crwdns120187:0crwdne120187:0 |
---|---|
crwdns120189:0crwdne120189:0 |
crwdns120191:0crwdne120191:0 crwdns120193:0crwdne120193:0 |
crwdns120195:0crwdne120195:0 |
crwdns120197:0:doc:crwdne120197:0 |
crwdns120199:0crwdne120199:0 |
crwdns120201:0crwdne120201:0 |
crwdns120203:0crwdne120203:0 |
crwdns120205:0crwdne120205:0 |
crwdns120207:0crwdne120207:0 |
crwdns120209:0crwdne120209:0 |
crwdns120211:0crwdne120211:0 |
crwdns120213:0:doc:crwdne120213:0 |
crwdns120215:0crwdne120215:0 |
crwdns120217:0:doc:crwdne120217:0 |
crwdns120219:0crwdne120219:0 |
crwdns120221:0crwdne120221:0 crwdns120223:0crwdne120223:0 |
crwdns120225:0crwdne120225:0 |
crwdns120227:0crwdne120227:0 |
crwdns120229:0crwdne120229:0
crwdns120231:0crwdne120231:0
crwdns120233:0:javadoc:crwdnd120233:0:javadoc:crwdne120233:0
crwdns120235:0crwdne120235:0
crwdns120237:0:doc:crwdne120237:0
crwdns120239:0crwdne120239: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
crwdns120241:0:doc:crwdne120241:0
crwdns120243:0crwdne120243:0
crwdns120245:0crwdne120245:0
crwdns120247:0:javadoc:crwdne120247: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
crwdns120249:0[player]crwdnd120249:0[player]crwdne120249:0
crwdns120251:0:doc:crwdne120251:0
crwdns120253:0crwdne120253:0
crwdns120255:0:javadoc:crwdnd120255:0:javadoc:crwdnd120255:0:javadoc:crwdnd120255:0:javadoc:crwdne120255:0
crwdns120257:0crwdne120257:0
crwdns120259:0crwdne120259:0
CommandResult result = CommandResult.builder()
.affectedEntities(42)
.successCount(1)
.build();
crwdns120261:0crwdne120261:0
crwdns120263:0crwdne120263:0
crwdns120265:0:javadoc:crwdnd120265:0:javadoc:crwdne120265:0