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:
Ross
2025-10-13 21:41:33 +02:00
committed by GitHub
parent 806b386cdb
commit 5753548b44
3 changed files with 32 additions and 3 deletions

View File

@@ -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();

View File

@@ -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);
}