mirror of
https://github.com/PaperMC/Velocity.git
synced 2024-11-27 06:30:35 +08:00
Fix tab complete for proxy commands for 1.12.2 and below and fix command tab complete repeating suggestions
This commit is contained in:
parent
c88a3807e7
commit
7dffa7ce33
@ -412,8 +412,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
List<Offer> offers = new ArrayList<>();
|
||||
for (String suggestion : suggestions) {
|
||||
offers.add(new Offer(suggestion));
|
||||
for (String offer : suggestions) {
|
||||
offers.add(new Offer(offer));
|
||||
}
|
||||
int startPos = packet.getCommand().lastIndexOf(' ') + 1;
|
||||
if (startPos > 0) {
|
||||
@ -460,10 +460,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
String command = request.getCommand().substring(1);
|
||||
server.getCommandManager().offerSuggestions(player, command)
|
||||
.thenAcceptAsync(offers -> {
|
||||
boolean needsSlash = player.getProtocolVersion().compareTo(MINECRAFT_1_13) < 0;
|
||||
boolean legacy = player.getProtocolVersion().compareTo(MINECRAFT_1_13) < 0;
|
||||
try {
|
||||
for (String offer : offers) {
|
||||
response.getOffers().add(new Offer(needsSlash ? "/" + offer : offer, null));
|
||||
offer = legacy && !offer.startsWith("/") ? "/" + offer : offer;
|
||||
if (legacy && offer.startsWith(command)) {
|
||||
offer = offer.substring(command.length());
|
||||
}
|
||||
response.getOffers().add(new Offer(offer, null));
|
||||
}
|
||||
response.getOffers().sort(null);
|
||||
player.getConnection().write(response);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.velocitypowered.proxy.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
@ -19,6 +20,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
*/
|
||||
public final class BrigadierUtils {
|
||||
|
||||
private static final Splitter SPACE_SPLITTER = Splitter.on(' ');
|
||||
|
||||
/**
|
||||
* Returns a literal node that redirects its execution to
|
||||
* the given destination node.
|
||||
@ -103,7 +106,7 @@ public final class BrigadierUtils {
|
||||
if (line.isEmpty()) {
|
||||
return new String[0];
|
||||
}
|
||||
return line.trim().split(" ", -1);
|
||||
return SPACE_SPLITTER.splitToList(line).toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user