crwdns130915:0crwdne130915:0

crwdns130917:0crwdne130917:0

crwdns130919:0:javadoc:crwdnd130919:0:javadoc:crwdne130919:0

crwdns130921:0:javadoc:crwdne130921:0

Tip

crwdns130923:0:javadoc:crwdne130923:0

crwdns130925:0:javadoc:crwdnd130925:0:javadoc:crwdne130925:0

crwdns130927:0:javadoc:crwdnd130927:0:javadoc:crwdne130927:0

crwdns130929:0crwdne130929: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;

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(new CommandExecutor() {
            @Override
            public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

                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");

crwdns130931:0crwdne130931:0

crwdns130933:0crwdne130933:0

crwdns130935:0crwdne130935:0

crwdns130937:0crwdne130937:0

crwdns130939:0crwdne130939:0

crwdns130941:0crwdne130941:0

crwdns130943:0crwdne130943:0

crwdns130945:0crwdne130945:0

crwdns130947:0crwdne130947:0

crwdns130949:0crwdne130949:0

crwdns130951:0crwdne130951:0

crwdns130953:0crwdne130953:0

crwdns130949:0crwdne130949:0

crwdns130955:0crwdne130955:0

crwdns130957:0crwdne130957:0

crwdns130959:0crwdne130959:0

crwdns130961:0crwdne130961:0

crwdns130963:0crwdne130963:0

crwdns130965:0crwdne130965:0

crwdns130967:0crwdne130967:0

crwdns130969:0crwdne130969:0

crwdns130971:0crwdne130971:0

crwdns130973:0crwdne130973:0

crwdns130975:0crwdne130975:0

crwdns130977:0crwdne130977:0

crwdns130979:0crwdne130979:0

crwdns130981:0crwdne130981:0

crwdns130983:0crwdne130983:0

crwdns130979:0crwdne130979:0

crwdns130985:0crwdne130985:0

crwdns130987:0crwdne130987:0

crwdns130989:0crwdne130989:0

crwdns130991:0crwdne130991:0

crwdns130993:0crwdne130993:0

crwdns130995:0crwdne130995:0

crwdns130997:0crwdne130997:0

crwdns130999:0crwdne130999:0

crwdns131001:0crwdne131001:0

crwdns131003:0crwdne131003:0

crwdns131005:0crwdne131005:0

crwdns131007:0crwdne131007:0

crwdns131009:0crwdne131009:0

crwdns131011:0crwdne131011:0

crwdns131013:0crwdne131013:0

crwdns131015:0crwdne131015:0

crwdns131017:0:javadoc:crwdne131017:0

crwdns131019:0crwdne131019:0

crwdns131021:0crwdne131021:0

crwdns131023:0crwdne131023:0

crwdns131025:0crwdne131025:0

crwdns131027:0crwdne131027:0

crwdns131029:0crwdne131029:0

crwdns131031:0crwdne131031:0

crwdns131027:0crwdne131027:0

crwdns131033:0crwdne131033:0

crwdns131035:0crwdne131035:0

crwdns131037:0crwdne131037:0

crwdns131039:0crwdne131039:0

crwdns131041:0crwdne131041:0

crwdns131043:0crwdne131043:0

crwdns131045:0crwdne131045:0

crwdns131047:0crwdne131047:0

crwdns131049:0crwdne131049:0

crwdns131051:0crwdne131051:0

crwdns131053:0crwdne131053:0

crwdns131055:0crwdne131055:0

crwdns131057:0crwdne131057:0

crwdns131053:0crwdne131053:0

crwdns131059:0crwdne131059:0

crwdns131061:0crwdne131061:0

crwdns131047:0crwdne131047:0

crwdns131063:0crwdne131063:0

crwdns131065:0crwdne131065:0

crwdns131047:0crwdne131047:0

crwdns131067:0crwdne131067:0

crwdns131069:0crwdne131069:0

crwdns131047:0crwdne131047:0

crwdns131071:0crwdne131071:0

crwdns131073:0crwdne131073:0

crwdns131047:0crwdne131047:0

crwdns131075:0crwdne131075:0

crwdns131077:0[-a]crwdne131077:0

crwdns131079:0:doc:crwdne131079:0

crwdns131081:0crwdne131081:0

crwdns131083:0crwdne131083:0

crwdns131085:0crwdne131085:0

crwdns131087:0crwdne131087:0

crwdns131089:0crwdne131089:0

crwdns131047:0crwdne131047:0

Tip

crwdns131091:0:javadoc:crwdne131091:0

crwdns131093:0crwdne131093:0

crwdns131095:0crwdne131095:0

crwdns131097:0:javadoc:crwdnd131097:0:javadoc:crwdnd131097:0:javadoc:crwdne131097:0

crwdns131099:0:javadoc:crwdnd131099:0:javadoc:crwdne131099:0

crwdns131101:0crwdne131101:0

crwdns131103:0crwdne131103: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 {
    CommandArgs errorargs;

    protected Vector2iCommandElement(Text key) {
        super(key);
    }

    @Override
    protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {

        // <x> <y>
        errorargs=args;

        String xInput = args.next();
        int x = parseInt(xInput);

        String yInput = args.next();
        int y = parseInt(yInput);

        return new Vector2i(x, y);
    }

    private int parseInt(String input) throws ArgumentParseException {
        try {
            return Integer.parseInt(input);
        } catch(NumberFormatException e) {
            throw errorargs.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>");
    }
}

crwdns131105:0crwdne131105: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

crwdns131107:0crwdne131107:0