diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index a007d454..75aebc65 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -1,17 +1,24 @@ package net.md_5.bungee.connection; +import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.StringRange; +import com.mojang.brigadier.suggestion.Suggestion; import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.tree.LiteralCommandNode; import java.io.DataInput; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.Unpooled; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; import net.md_5.bungee.BungeeCord; @@ -497,16 +504,44 @@ public class DownstreamBridge extends PacketHandler @Override public void handle(TabCompleteResponse tabCompleteResponse) throws Exception { - if ( tabCompleteResponse.getCommands() == null ) + List commands = tabCompleteResponse.getCommands(); + if ( commands == null ) { - // Passthrough on 1.13 style command responses - unclear of a sane way to process them at the moment, contributions welcome - return; + commands = Lists.transform( tabCompleteResponse.getSuggestions().getList(), new Function() + { + @Override + public String apply(Suggestion input) + { + return input.getText(); + } + } ); } - TabCompleteResponseEvent tabCompleteResponseEvent = new TabCompleteResponseEvent( server, con, tabCompleteResponse.getCommands() ); - + TabCompleteResponseEvent tabCompleteResponseEvent = new TabCompleteResponseEvent( server, con, new ArrayList<>( commands ) ); if ( !bungee.getPluginManager().callEvent( tabCompleteResponseEvent ).isCancelled() ) { + // Take action only if modified + if ( !commands.equals( tabCompleteResponseEvent.getSuggestions() ) ) + { + if ( tabCompleteResponse.getCommands() != null ) + { + // Classic style + tabCompleteResponse.setCommands( tabCompleteResponseEvent.getSuggestions() ); + } else + { + // Brigadier style + final StringRange range = tabCompleteResponse.getSuggestions().getRange(); + tabCompleteResponse.setSuggestions( new Suggestions( range, Lists.transform( tabCompleteResponseEvent.getSuggestions(), new Function() + { + @Override + public Suggestion apply(String input) + { + return new Suggestion( range, input ); + } + } ) ) ); + } + } + con.unsafe().sendPacket( tabCompleteResponse ); }