crwdns150179:0crwdne150179:0

crwdns150181:0crwdne150181:0

crwdns150183:0:javadoc:crwdnd150183:0:javadoc:crwdne150183:0

crwdns150185:0:javadoc:crwdne150185:0

Tip

crwdns150187:0:javadoc:crwdne150187:0

crwdns150189:0:javadoc:crwdnd150189:0:javadoc:crwdne150189:0

crwdns150191:0:javadoc:crwdnd150191:0:javadoc:crwdne150191:0

crwdns150193:0crwdne150193: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");

crwdns150195:0crwdne150195:0

crwdns150197:0crwdne150197:0

crwdns150199:0crwdne150199:0

crwdns150201:0crwdne150201:0

crwdns150203:0crwdne150203:0

crwdns150205:0crwdne150205:0

crwdns150207:0crwdne150207:0

crwdns150209:0crwdne150209:0

crwdns150211:0crwdne150211:0

crwdns150213:0crwdne150213:0

crwdns150215:0crwdne150215:0

crwdns150217:0crwdne150217:0

crwdns150213:0crwdne150213:0

crwdns150219:0crwdne150219:0

crwdns150221:0crwdne150221:0

crwdns150223:0crwdne150223:0

crwdns150225:0crwdne150225:0

crwdns150227:0crwdne150227:0

crwdns150229:0crwdne150229:0

crwdns150231:0crwdne150231:0

crwdns150233:0crwdne150233:0

crwdns150235:0crwdne150235:0

crwdns150237:0crwdne150237:0

crwdns150239:0crwdne150239:0

crwdns150241:0crwdne150241:0

crwdns150243:0crwdne150243:0

crwdns150245:0crwdne150245:0

crwdns150247:0crwdne150247:0

crwdns150243:0crwdne150243:0

crwdns150249:0crwdne150249:0

crwdns150251:0crwdne150251:0

crwdns150253:0crwdne150253:0

crwdns150255:0crwdne150255:0

crwdns150257:0crwdne150257:0

crwdns150259:0crwdne150259:0

crwdns150261:0crwdne150261:0

crwdns150263:0crwdne150263:0

crwdns150265:0crwdne150265:0

crwdns150267:0crwdne150267:0

crwdns150269:0crwdne150269:0

crwdns150271:0crwdne150271:0

crwdns150273:0crwdne150273:0

crwdns150275:0crwdne150275:0

crwdns150277:0crwdne150277:0

crwdns150279:0crwdne150279:0

crwdns150281:0:javadoc:crwdne150281:0

crwdns150283:0crwdne150283:0

crwdns150285:0crwdne150285:0

crwdns150287:0crwdne150287:0

crwdns150289:0crwdne150289:0

crwdns150291:0crwdne150291:0

crwdns150293:0crwdne150293:0

crwdns150295:0crwdne150295:0

crwdns150291:0crwdne150291:0

crwdns150297:0crwdne150297:0

crwdns150299:0crwdne150299:0

crwdns150301:0crwdne150301:0

crwdns150303:0crwdne150303:0

crwdns150305:0crwdne150305:0

crwdns150307:0crwdne150307:0

crwdns150309:0crwdne150309:0

crwdns150311:0crwdne150311:0

crwdns150313:0crwdne150313:0

crwdns150315:0crwdne150315:0

crwdns150317:0crwdne150317:0

crwdns150319:0crwdne150319:0

crwdns150321:0crwdne150321:0

crwdns150317:0crwdne150317:0

crwdns150323:0crwdne150323:0

crwdns150325:0crwdne150325:0

crwdns150311:0crwdne150311:0

crwdns150327:0crwdne150327:0

crwdns150329:0crwdne150329:0

crwdns150311:0crwdne150311:0

crwdns150331:0crwdne150331:0

crwdns150333:0crwdne150333:0

crwdns150311:0crwdne150311:0

crwdns150335:0crwdne150335:0

crwdns150337:0crwdne150337:0

crwdns150311:0crwdne150311:0

crwdns150339:0crwdne150339:0

crwdns150341:0[-a]crwdne150341:0

crwdns150343:0:doc:crwdne150343:0

crwdns150345:0crwdne150345:0

crwdns150347:0crwdne150347:0

crwdns150349:0crwdne150349:0

crwdns150351:0crwdne150351:0

crwdns150353:0crwdne150353:0

crwdns150311:0crwdne150311:0

Tip

crwdns150355:0:javadoc:crwdne150355:0

crwdns150357:0crwdne150357:0

crwdns150359:0crwdne150359:0

crwdns150361:0:javadoc:crwdnd150361:0:javadoc:crwdnd150361:0:javadoc:crwdne150361:0

crwdns150363:0:javadoc:crwdnd150363:0:javadoc:crwdne150363:0

crwdns150365:0crwdne150365:0

crwdns150367:0crwdne150367: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>");
    }
}

crwdns150369:0crwdne150369: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

crwdns150371:0crwdne150371:0