#2586: TabCompleteResponseEvent for 1.13
This commit is contained in:
parent
7496b0a2c8
commit
29c093f83f
@ -1,17 +1,24 @@
|
|||||||
package net.md_5.bungee.connection;
|
package net.md_5.bungee.connection;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
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.SuggestionProvider;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufAllocator;
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import net.md_5.bungee.BungeeCord;
|
||||||
@ -497,16 +504,44 @@ public class DownstreamBridge extends PacketHandler
|
|||||||
@Override
|
@Override
|
||||||
public void handle(TabCompleteResponse tabCompleteResponse) throws Exception
|
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
|
commands = Lists.transform( tabCompleteResponse.getSuggestions().getList(), new Function<Suggestion, String>()
|
||||||
return;
|
{
|
||||||
|
@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() )
|
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 );
|
con.unsafe().sendPacket( tabCompleteResponse );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user