use of org.spongepowered.api.command.parameter.managed.ValueParser in project SpongeCommon by SpongePowered.
the class SpongeParameterValueBuilder method build.
@Override
@NonNull
public SpongeParameterValue<T> build() throws IllegalStateException {
Preconditions.checkState(this.key != null, "The command key may not be null");
Preconditions.checkState(!this.parsers.isEmpty(), "There must be parsers");
final ImmutableList.Builder<ValueParser<? extends T>> parsersBuilder = ImmutableList.builder();
parsersBuilder.addAll(this.parsers);
final ValueCompleter completer;
if (this.completer != null) {
completer = this.completer;
} else {
final ImmutableList.Builder<ValueCompleter> completersBuilder = ImmutableList.builder();
for (final ValueParser<? extends T> parser : this.parsers) {
if (parser instanceof ValueCompleter) {
completersBuilder.add((ValueCompleter) parser);
}
}
final ImmutableList<ValueCompleter> completers = completersBuilder.build();
if (completers.isEmpty()) {
completer = SpongeParameterValueBuilder.EMPTY_COMPLETER;
} else if (completers.size() == 1) {
completer = completers.get(0);
} else {
completer = (context, currentInput) -> {
final ImmutableList.Builder<CommandCompletion> builder = ImmutableList.builder();
for (final ValueCompleter valueCompleter : completers) {
builder.addAll(valueCompleter.complete(context, currentInput));
}
return builder.build();
};
}
}
return new SpongeParameterValue<>(parsersBuilder.build(), completer, this.usage, this.executionRequirements == null ? commandCause -> true : this.executionRequirements, this.key, this.isOptional, this.consumesAll, this.terminal, this.modifier);
}
Aggregations