Search in sources :

Example 1 with ParsedArgument

use of com.mojang.brigadier.context.ParsedArgument in project SpongeCommon by SpongePowered.

the class SpongeArgumentCommandNode method parse.

@Override
public final void parse(final StringReader reader, final CommandContextBuilder<CommandSourceStack> contextBuilder) throws CommandSyntaxException {
    final int start = reader.getCursor();
    final SpongeCommandContextBuilder builder = (SpongeCommandContextBuilder) contextBuilder;
    final T result = this.parser.parse(this.key, builder, (SpongeStringReader) reader, this.modifier);
    if (result != null) {
        builder.putEntry(this.key, result);
        final ParsedArgument<CommandSourceStack, T> parsed = new ParsedArgument<>(start, reader.getCursor(), result);
        builder.withArgumentInternal(this.getName(), parsed, false);
        builder.withNode(this, parsed.getRange());
    } else if (this.parser.doesNotRead()) {
        // Assume this is a null "optional" parser and add the node as read so that we dont end up with an empty context
        builder.withNode(this, StringRange.at(start));
    }
}
Also used : ParsedArgument(com.mojang.brigadier.context.ParsedArgument) CommandSourceStack(net.minecraft.commands.CommandSourceStack) SpongeCommandContextBuilder(org.spongepowered.common.command.brigadier.context.SpongeCommandContextBuilder)

Aggregations

ParsedArgument (com.mojang.brigadier.context.ParsedArgument)1 CommandSourceStack (net.minecraft.commands.CommandSourceStack)1 SpongeCommandContextBuilder (org.spongepowered.common.command.brigadier.context.SpongeCommandContextBuilder)1