mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 03:05:49 +01:00
#2586: TabCompleteResponseEvent for 1.13
This commit is contained in:
parent
7496b0a2c8
commit
29c093f83f
@ -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<String> 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<Suggestion, String>()
|
||||
{
|
||||
@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<String, Suggestion>()
|
||||
{
|
||||
@Override
|
||||
public Suggestion apply(String input)
|
||||
{
|
||||
return new Suggestion( range, input );
|
||||
}
|
||||
} ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
con.unsafe().sendPacket( tabCompleteResponse );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user