mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-04-20 03:18:17 +02:00
Fix SimpleCommand suggestion offset (#1664)
* Fix command suggestion offset * fix length error * add test * checkstyle --------- Co-authored-by: Ross <2086824-trashp@users.noreply.gitlab.com>
This commit is contained in:
@@ -103,13 +103,17 @@ abstract class InvocableCommandRegistrar<T extends InvocableCommand<I>,
|
||||
.requiresWithContext((context, reader) -> requirement.test(context))
|
||||
.executes(callback)
|
||||
.suggests((context, builder) -> {
|
||||
// Offset the suggestion to the last space seperated word
|
||||
int lastSpace = builder.getRemaining().lastIndexOf(' ') + 1;
|
||||
final var offsetBuilder = builder.createOffset(builder.getStart() + lastSpace);
|
||||
|
||||
final I invocation = invocationFactory.create(context);
|
||||
return command.suggestAsync(invocation).thenApply(suggestions -> {
|
||||
for (String value : suggestions) {
|
||||
Preconditions.checkNotNull(value, "suggestion");
|
||||
builder.suggest(value);
|
||||
offsetBuilder.suggest(value);
|
||||
}
|
||||
return builder.build();
|
||||
return offsetBuilder.build();
|
||||
});
|
||||
})
|
||||
.build();
|
||||
|
||||
@@ -724,7 +724,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
TabCompleteResponsePacket resp = new TabCompleteResponsePacket();
|
||||
resp.setTransactionId(packet.getTransactionId());
|
||||
resp.setStart(startPos + 1);
|
||||
resp.setLength(packet.getCommand().length() - startPos);
|
||||
resp.setLength(packet.getCommand().length() - startPos - 1);
|
||||
resp.getOffers().addAll(offers);
|
||||
player.getConnection().write(resp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user