crwdns120267:0crwdne120267:0
crwdns120269:0crwdne120269:0
crwdns120271:0:javadoc:crwdnd120271:0:javadoc:crwdne120271:0
crwdns120273:0:javadoc:crwdne120273:0
crwdns120275:0crwdne120275:0
Tip
crwdns120277:0:javadoc:crwdne120277:0
crwdns120279:0:javadoc:crwdnd120279:0:javadoc:crwdne120279:0
crwdns120281:0:javadoc:crwdnd120281:0:javadoc:crwdne120281:0
crwdns120283:0crwdne120283:0
import org.spongepowered.api.Sponge;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.entity.living.player.Player;
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.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.command.spec.CommandSpec;
PluginContainer plugin = ...;
CommandSpec myCommandSpec = CommandSpec.builder()
.description(Text.of("Send a message to a player"))
.permission("myplugin.command.message")
.arguments(
GenericArguments.onlyOne(GenericArguments.player(Text.of("player"))),
GenericArguments.remainingJoinedStrings(Text.of("message")))
.executor((CommandSource src, CommandContext args) -> {
Player player = args.<Player>getOne("player").get();
String message = args.<String>getOne("message").get();
player.sendMessage(Text.of(message));
return CommandResult.success();
})
.build();
Sponge.getCommandManager().register(plugin, myCommandSpec, "message", "msg", "m");
crwdns120285:0crwdne120285:0
crwdns120287:0crwdne120287:0 |
crwdns120289:0crwdne120289:0 |
crwdns120291:0crwdne120291:0 |
---|---|---|
crwdns120293:0crwdne120293:0 |
crwdns120295:0crwdne120295:0 |
|
crwdns120297:0crwdne120297:0 |
||
crwdns120299:0crwdne120299:0 |
crwdns120301:0crwdne120301:0 |
crwdns120303:0crwdne120303:0 |
crwdns120305:0crwdne120305:0 |
crwdns120307:0crwdne120307:0 |
crwdns120303:0crwdne120303:0 |
crwdns120309:0crwdne120309:0 |
crwdns120311:0crwdne120311:0 |
crwdns120313:0crwdne120313:0 |
crwdns120315:0crwdne120315:0 |
crwdns120317:0crwdne120317:0 |
crwdns120319:0crwdne120319:0 |
crwdns120321:0crwdne120321:0 |
crwdns120323:0crwdne120323:0 |
crwdns120325:0crwdne120325:0 |
crwdns120327:0crwdne120327:0 |
||
crwdns120329:0crwdne120329:0 |
crwdns120331:0crwdne120331:0 |
crwdns120333:0crwdne120333:0 |
crwdns120335:0crwdne120335:0 |
crwdns120337:0crwdne120337:0 |
crwdns120333:0crwdne120333:0 |
crwdns120339:0crwdne120339:0 |
crwdns120341:0crwdne120341:0 |
crwdns120343:0crwdne120343:0 |
crwdns120345:0crwdne120345:0 |
crwdns120347:0crwdne120347:0 |
crwdns120349:0crwdne120349:0 |
crwdns120351:0crwdne120351:0 |
crwdns120353:0crwdne120353:0 |
crwdns120355:0crwdne120355:0 |
crwdns120357:0crwdne120357:0 |
crwdns120359:0crwdne120359:0 |
crwdns120361:0crwdne120361:0 |
crwdns120363:0crwdne120363:0 |
crwdns120365:0crwdne120365:0 |
crwdns120367:0crwdne120367:0 |
crwdns120369:0crwdne120369:0 |
crwdns120371:0:javadoc:crwdne120371:0 |
crwdns120373:0crwdne120373:0 |
crwdns120375:0crwdne120375:0 |
||
crwdns120377:0crwdne120377:0 |
crwdns120379:0crwdne120379:0 |
crwdns120381:0crwdne120381:0 |
crwdns120383:0crwdne120383:0 |
crwdns120385:0crwdne120385:0 |
crwdns120381:0crwdne120381:0 |
crwdns120387:0crwdne120387:0 |
crwdns120389:0crwdne120389:0 |
crwdns120391:0crwdne120391:0 |
crwdns120393:0crwdne120393:0 crwdns120395:0crwdne120395:0 |
||
crwdns120397:0crwdne120397:0 |
crwdns120399:0crwdne120399:0 |
crwdns120401:0crwdne120401:0 |
crwdns120403:0crwdne120403:0 |
crwdns120405:0crwdne120405:0 |
crwdns120407:0crwdne120407:0 |
crwdns120409:0crwdne120409:0 |
crwdns120411:0crwdne120411:0 |
crwdns120407:0crwdne120407:0 |
crwdns120413:0crwdne120413:0 |
crwdns120415:0crwdne120415:0 |
crwdns120401:0crwdne120401:0 |
crwdns120417:0crwdne120417:0 |
crwdns120419:0crwdne120419:0 |
crwdns120401:0crwdne120401:0 |
crwdns120421:0crwdne120421:0 |
crwdns120423:0crwdne120423:0 |
crwdns120401:0crwdne120401:0 |
crwdns120425:0crwdne120425:0 |
crwdns120427:0crwdne120427:0 |
crwdns120401:0crwdne120401:0 |
crwdns120429:0crwdne120429:0 |
crwdns120431:0[-a]crwdne120431:0 crwdns120433:0:doc:crwdne120433:0 |
crwdns120435:0crwdne120435:0 crwdns120437:0crwdne120437:0 crwdns120439:0crwdne120439:0 |
crwdns120441:0crwdne120441:0 |
crwdns120443:0crwdne120443:0 |
crwdns120401:0crwdne120401:0 |
crwdns120445:0crwdne120445:0 |
crwdns120447:0crwdne120447:0 |
crwdns120401:0crwdne120401:0 |
Tip
crwdns120449:0:javadoc:crwdne120449:0
Warning
crwdns120451:0crwdne120451:0
crwdns120453:0crwdne120453:0
crwdns120455:0crwdne120455:0
crwdns120457:0:javadoc:crwdnd120457:0:javadoc:crwdnd120457:0:javadoc:crwdne120457:0
crwdns120459:0:javadoc:crwdnd120459:0:javadoc:crwdne120459:0
crwdns120461:0crwdne120461:0
crwdns120463:0crwdne120463:0
import com.flowpowered.math.vector.Vector2i;
import org.spongepowered.api.command.args.ArgumentParseException;
import org.spongepowered.api.command.args.CommandArgs;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.command.args.CommandElement;
import java.util.Collections;
import java.util.List;
public class Vector2iCommandElement extends CommandElement {
protected Vector2iCommandElement(Text key) {
super(key);
}
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
String xInput = args.next();
int x = parseInt(xInput, args);
String yInput = args.next();
int y = parseInt(yInput, args);
return new Vector2i(x, y);
}
private int parseInt(String input, CommandArgs args) throws ArgumentParseException {
try {
return Integer.parseInt(input);
} catch(NumberFormatException e) {
throw args.createError(Text.of("'" + input + "' is not a valid number!"));
}
}
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
return Collections.emptyList();
}
@Override
public Text getUsage(CommandSource src) {
return Text.of("<x> <y>");
}
}
crwdns120465:0crwdne120465:0
// /plottp <x> <y>
CommandSpec myCommandSpec = CommandSpec.builder()
.description(Text.of("Teleport to a plot"))
.permission("myplugin.command.plot.tp")
.arguments(new Vector2iCommandElement(Text.of("coordinates")))
.executor(new MyCommandExecutor())
.build();
Tip
crwdns120467:0crwdne120467:0
crwdns120469:0crwdne120469:0
crwdns120471:0:javadoc:crwdnd120471:0:javadoc:crwdne120471:0
crwdns120473:0:javadoc:crwdnd120473:0:javadoc:crwdne120473:0
crwdns120475:0:javadoc:crwdne120475:0
crwdns120477:0crwdne120477:0
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
String nextArg = args.next();
if (nextArg.startsWith("@")) {
Set<Entity> selectedEntities;
try {
selectedEntities = Selector.parse(nextArg).resolve(source);
} catch (IllegalArgumentException e) {
throw args.createError(Text.of("Could not parse selector."));
}
if (selectedEntities.isEmpty()) {
throw args.createError(Text.of("No entities selected."));
}
return selectedEntities;
}
throw args.createError(Text.of("Not a selector."));
}
Tip
crwdns120479:0crwdne120479:0