Java Code Examples for com.mojang.brigadier.suggestion.SuggestionsBuilder#getInput()

The following examples show how to use com.mojang.brigadier.suggestion.SuggestionsBuilder#getInput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityArgumentType_1_12_2.java    From multiconnect with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
    if (!(context.getSource() instanceof CommandSource))
        return builder.buildFuture();

    StringReader reader = new StringReader(builder.getInput());
    reader.setCursor(builder.getStart());

    CompletableFuture<Suggestions> playerCompletions;
    if ((reader.canRead() && reader.peek() == '@') || !suggestPlayerNames) {
        playerCompletions = Suggestions.empty();
    } else {
        playerCompletions = ((CommandSource) context.getSource()).getCompletions((CommandContext<CommandSource>) context, builder.restart());
    }

    EntitySelectorParser parser = new EntitySelectorParser(reader, singleTarget, playersOnly);
    try {
        parser.parse();
    } catch (CommandSyntaxException ignore) {
    }
    CompletableFuture<Suggestions> selectorCompletions = parser.suggestor.apply(builder.restart());

    return CompletableFuture.allOf(playerCompletions, selectorCompletions)
            .thenCompose(v -> UnionArgumentType.mergeSuggestions(playerCompletions.join(), selectorCompletions.join()));
}
 
Example 2
Source File: CommandArgumentType.java    From multiconnect with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
    CommandDispatcher<S> dispatcher = ((CommandDispatcher<S>) this.dispatcher);
    StringReader reader = new StringReader(builder.getInput());
    reader.setCursor(builder.getStart());
    ParseResults<S> results = dispatcher.parse(reader, context.getSource());
    return dispatcher.getCompletionSuggestions(results);
}
 
Example 3
Source File: PointTypeTest.java    From Chimera with MIT License 5 votes vote down vote up
@ParameterizedTest
@MethodSource("suggest_parameters")
void suggest(String[] parts, SuggestionsBuilder expected) {
    var suggestions = new SuggestionsBuilder(expected.getInput(), 0);
    type.suggest(suggestions, parts);
    
    assertEquals(expected.build(), suggestions.build());
}
 
Example 4
Source File: PointTypeTest.java    From Chimera with MIT License 5 votes vote down vote up
@ParameterizedTest
@MethodSource("suggest_parameters")
void suggest(String[] parts, SuggestionsBuilder expected) {
    var suggestions = new SuggestionsBuilder(expected.getInput(), 0);
    type.suggest(suggestions, parts);
    
    assertEquals(expected.build(), suggestions.build());
}
 
Example 5
Source File: TPArgumentType.java    From multiconnect with MIT License 4 votes vote down vote up
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
    List<CompletableFuture<Suggestions>> suggestions = new ArrayList<>();

    String[] args = builder.getRemaining().split(" ", -1);
    if (args.length == 1) {
        suggestions.add(blockPos.listSuggestions(context, builder.restart()));
        suggestions.add(victim.listSuggestions(context, builder.restart()));
        suggestions.add(target.listSuggestions(context, builder.restart()));
    } else {
        StringReader reader = new StringReader(builder.getInput());
        reader.setCursor(builder.getStart());

        boolean victimPresent = !isCoordinateArg(reader);
        if (victimPresent) {
            reader.setCursor(builder.getStart());
            try {
                victim.parse(reader);
            } catch (CommandSyntaxException e) {
                return builder.buildFuture();
            }
            if (reader.peek() != ' ')
                return builder.buildFuture();
        }
        reader.skip();
        if (args.length == 2) {
            if (victimPresent) {
                suggestions.add(blockPos.listSuggestions(context, builder.createOffset(reader.getCursor())));
                suggestions.add(target.listSuggestions(context, builder.createOffset(reader.getCursor())));
            } else {
                suggestions.add(blockPos.listSuggestions(context, builder.restart()));
            }
        } else {
            int argStart = victimPresent ? reader.getCursor() : builder.getStart();
            if (!isCoordinateArg(reader))
                return builder.buildFuture();
            if (args.length <= (victimPresent ? 4 : 3)) {
                suggestions.add(blockPos.listSuggestions(context, builder.createOffset(argStart)));
            } else {
                if (victimPresent) {
                    reader.skip();
                    isCoordinateArg(reader);
                }
                reader.skip();
                isCoordinateArg(reader);
                reader.skip();
                suggestions.add(CommandSource.suggestMatching(new String[] {"~", "~ ~"}, builder.createOffset(reader.getCursor())));
            }
        }
    }

    return CompletableFuture.allOf(suggestions.toArray(new CompletableFuture[0]))
            .thenApply(v -> Suggestions.merge(builder.getInput(), suggestions.stream().map(CompletableFuture::join).collect(Collectors.toList())));
}