#2479: Allow injection of BungeeCord commands to 1.13 with inject_commands option
This commit is contained in:
@@ -60,6 +60,7 @@ public class Configuration implements ProxyConfig
|
||||
private int compressionThreshold = 256;
|
||||
private boolean preventProxyConnections;
|
||||
private boolean forgeSupport;
|
||||
private boolean injectCommands;
|
||||
|
||||
public void load()
|
||||
{
|
||||
@@ -90,6 +91,11 @@ public class Configuration implements ProxyConfig
|
||||
compressionThreshold = adapter.getInt( "network_compression_threshold", compressionThreshold );
|
||||
preventProxyConnections = adapter.getBoolean( "prevent_proxy_connections", preventProxyConnections );
|
||||
forgeSupport = adapter.getBoolean( "forge_support", forgeSupport );
|
||||
injectCommands = adapter.getBoolean( "inject_commands", injectCommands );
|
||||
if ( injectCommands )
|
||||
{
|
||||
System.setProperty( "net.md-5.bungee.protocol.register_commands", "true" );
|
||||
}
|
||||
|
||||
disabledCommands = new CaseInsensitiveSet( (Collection<String>) adapter.getList( "disabled_commands", Arrays.asList( "disabledcommandhere" ) ) );
|
||||
|
||||
|
@@ -3,11 +3,17 @@ package net.md_5.bungee.connection;
|
||||
import com.google.common.base.Preconditions;
|
||||
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.suggestion.SuggestionProvider;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.ServerConnection;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.event.ServerDisconnectEvent;
|
||||
@@ -32,6 +38,7 @@ import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
import net.md_5.bungee.protocol.packet.BossBar;
|
||||
import net.md_5.bungee.protocol.packet.Commands;
|
||||
import net.md_5.bungee.protocol.packet.KeepAlive;
|
||||
import net.md_5.bungee.protocol.packet.PlayerListItem;
|
||||
import net.md_5.bungee.protocol.packet.Respawn;
|
||||
@@ -526,6 +533,35 @@ public class DownstreamBridge extends PacketHandler
|
||||
con.setDimension( respawn.getDimension() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Commands commands) throws Exception
|
||||
{
|
||||
boolean modified = false;
|
||||
|
||||
if ( BungeeCord.getInstance().config.isInjectCommands() )
|
||||
{
|
||||
for ( String command : bungee.getPluginManager().getCommands() )
|
||||
{
|
||||
if ( commands.getRoot().getChild( command ) == null )
|
||||
{
|
||||
LiteralCommandNode dummy = LiteralArgumentBuilder.literal( command )
|
||||
.then( RequiredArgumentBuilder.argument( "args", StringArgumentType.greedyString() )
|
||||
.suggests( Commands.SuggestionRegistry.ASK_SERVER ) )
|
||||
.build();
|
||||
commands.getRoot().addChild( dummy );
|
||||
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( modified )
|
||||
{
|
||||
con.unsafe().sendPacket( commands );
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@@ -1,8 +1,12 @@
|
||||
package net.md_5.bungee.connection;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.mojang.brigadier.context.StringRange;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import io.netty.channel.Channel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
@@ -172,6 +176,19 @@ public class UpstreamBridge extends PacketHandler
|
||||
if ( con.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_13 )
|
||||
{
|
||||
con.unsafe().sendPacket( new TabCompleteResponse( results ) );
|
||||
} else if ( BungeeCord.getInstance().config.isInjectCommands() )
|
||||
{
|
||||
int start = tabComplete.getCursor().lastIndexOf( ' ' ) + 1;
|
||||
int end = tabComplete.getCursor().length();
|
||||
StringRange range = StringRange.between( start, end );
|
||||
|
||||
List<Suggestion> brigadier = new LinkedList<>();
|
||||
for ( String s : results )
|
||||
{
|
||||
brigadier.add( new Suggestion( range, s ) );
|
||||
}
|
||||
|
||||
con.unsafe().sendPacket( new TabCompleteResponse( tabComplete.getTransactionId(), new Suggestions( range, brigadier ) ) );
|
||||
}
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user