🐛 Fix brigadier suggestion building

An offset will be added pointing to the last occurrence of a blank space. This fixes incorrect tab completions for greedy strings
This commit is contained in:
Alexander Söderberg 2020-10-13 19:53:01 +02:00
parent 5f466fcbc0
commit 06a34651bf
No known key found for this signature in database
GPG key ID: FACEA5B0F4C1BF80
3 changed files with 26 additions and 3 deletions

View file

@ -30,7 +30,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
* A flag is an optional command argument that may have an associated parser,
@ -160,7 +162,19 @@ public final class CommandFlag<T> {
* @return New builder instance
*/
public Builder<T> withAliases(final @NonNull String... aliases) {
return new Builder<>(this.name, aliases, this.description, this.commandArgument);
final Set<String> filteredAliases = new HashSet<>();
for (final String alias : aliases) {
if (alias.isEmpty()) {
continue;
}
filteredAliases.add(alias);
}
return new Builder<>(
this.name,
filteredAliases.toArray(new String[0]),
this.description,
this.commandArgument
);
}
/**