Search in sources :

Example 1 with SpongeCommandDispatcher

use of org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher in project SpongeCommon by SpongePowered.

the class SpongeParameterizedCommand method getCachedDispatcher.

private SpongeCommandDispatcher getCachedDispatcher() {
    if (this.cachedDispatcher == null) {
        if (this.commandManager == null) {
            throw new IllegalStateException("Completions cannot be requested for an unregistered parameterized command");
        }
        this.cachedDispatcher = new SpongeCommandDispatcher(this.commandManager);
        this.cachedDispatcher.register(this.buildWithAlias("command"));
    }
    return this.cachedDispatcher;
}
Also used : SpongeCommandDispatcher(org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher)

Example 2 with SpongeCommandDispatcher

use of org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher in project SpongeCommon by SpongePowered.

the class SpongeParameterizedCommand method complete.

@Override
public List<CommandCompletion> complete(@NonNull final CommandCause cause, final ArgumentReader.@NonNull Mutable arguments) {
    final SpongeCommandDispatcher dispatcher = this.getCachedDispatcher();
    final String input = arguments.remaining();
    final ParseResults<CommandSourceStack> parseResults = dispatcher.parse((StringReader) arguments, (CommandSourceStack) cause);
    final Suggestions suggestions = dispatcher.getCompletionSuggestions(parseResults).join();
    return suggestions.getList().stream().map(SpongeCommandCompletion::from).collect(Collectors.toList());
}
Also used : Suggestions(com.mojang.brigadier.suggestion.Suggestions) SpongeCommandDispatcher(org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher) CommandSourceStack(net.minecraft.commands.CommandSourceStack)

Example 3 with SpongeCommandDispatcher

use of org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher in project Sponge by SpongePowered.

the class SpongeParameterizedCommand method complete.

@Override
public List<CommandCompletion> complete(@NonNull final CommandCause cause, final ArgumentReader.@NonNull Mutable arguments) {
    final SpongeCommandDispatcher dispatcher = this.getCachedDispatcher();
    final String input = arguments.remaining();
    final ParseResults<CommandSourceStack> parseResults = dispatcher.parse((StringReader) arguments, (CommandSourceStack) cause);
    final Suggestions suggestions = dispatcher.getCompletionSuggestions(parseResults).join();
    return suggestions.getList().stream().map(SpongeCommandCompletion::from).collect(Collectors.toList());
}
Also used : Suggestions(com.mojang.brigadier.suggestion.Suggestions) SpongeCommandDispatcher(org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher) CommandSourceStack(net.minecraft.commands.CommandSourceStack)

Example 4 with SpongeCommandDispatcher

use of org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher in project Sponge by SpongePowered.

the class SpongeParameterizedCommand method getCachedDispatcher.

private SpongeCommandDispatcher getCachedDispatcher() {
    if (this.cachedDispatcher == null) {
        if (this.commandManager == null) {
            throw new IllegalStateException("Completions cannot be requested for an unregistered parameterized command");
        }
        this.cachedDispatcher = new SpongeCommandDispatcher(this.commandManager);
        this.cachedDispatcher.register(this.buildWithAlias("command"));
    }
    return this.cachedDispatcher;
}
Also used : SpongeCommandDispatcher(org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher)

Aggregations

SpongeCommandDispatcher (org.spongepowered.common.command.brigadier.dispatcher.SpongeCommandDispatcher)4 Suggestions (com.mojang.brigadier.suggestion.Suggestions)2 CommandSourceStack (net.minecraft.commands.CommandSourceStack)2