🐛 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:
parent
5f466fcbc0
commit
06a34651bf
3 changed files with 26 additions and 3 deletions
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -456,6 +456,13 @@ public final class CloudBrigadierManager<C, S> {
|
|||
command
|
||||
);
|
||||
|
||||
SuggestionsBuilder suggestionsBuilder = builder;
|
||||
|
||||
final int lastIndexOfSpaceInRemainingString = builder.getRemaining().lastIndexOf(' ');
|
||||
if (lastIndexOfSpaceInRemainingString != -1) {
|
||||
suggestionsBuilder = builder.createOffset(builder.getStart() + lastIndexOfSpaceInRemainingString + 1);
|
||||
}
|
||||
|
||||
for (final String suggestion : suggestions) {
|
||||
String tooltip = argument.getName();
|
||||
if (!(argument instanceof StaticArgument)) {
|
||||
|
|
@ -465,9 +472,10 @@ public final class CloudBrigadierManager<C, S> {
|
|||
tooltip = '[' + tooltip + ']';
|
||||
}
|
||||
}
|
||||
builder.suggest(suggestion, new LiteralMessage(tooltip));
|
||||
suggestionsBuilder = suggestionsBuilder.suggest(suggestion, new LiteralMessage(tooltip));
|
||||
}
|
||||
return builder.buildFuture();
|
||||
|
||||
return suggestionsBuilder.buildFuture();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.LinkedList;
|
|||
* {@link Caption} instances for messages in cloud-bukkit
|
||||
*/
|
||||
public final class BukkitCaptionKeys {
|
||||
|
||||
private static final Collection<Caption> RECOGNIZED_CAPTIONS = new LinkedList<>();
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue