#3246: Fix commands not working due to MinecraftForge changes

This commit is contained in:
md_5 2022-02-06 08:26:09 +11:00
parent 9c95d4ba43
commit d2d157c1fe
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -11,7 +11,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.StringRange;
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.mojang.brigadier.tree.CommandNode;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
@ -67,6 +67,13 @@ import net.md_5.bungee.tab.TabList;
public class DownstreamBridge extends PacketHandler
{
// #3246: Recent versions of MinecraftForge alter Vanilla behaviour and require a command so that the executable flag is set
// If the flag is not set, then the command will appear and successfully tab complete, but cannot be successfully executed
private static final com.mojang.brigadier.Command DUMMY_COMMAND = (context) ->
{
return 0;
};
//
private final ProxyServer bungee;
private final UserConnection con;
private final ServerConnection server;
@ -654,9 +661,9 @@ public class DownstreamBridge extends PacketHandler
{
if ( !bungee.getDisabledCommands().contains( command.getKey() ) && commands.getRoot().getChild( command.getKey() ) == null && command.getValue().hasPermission( con ) )
{
LiteralCommandNode dummy = LiteralArgumentBuilder.literal( command.getKey() )
CommandNode dummy = LiteralArgumentBuilder.literal( command.getKey() ).executes( DUMMY_COMMAND )
.then( RequiredArgumentBuilder.argument( "args", StringArgumentType.greedyString() )
.suggests( Commands.SuggestionRegistry.ASK_SERVER ) )
.suggests( Commands.SuggestionRegistry.ASK_SERVER ).executes( DUMMY_COMMAND ) )
.build();
commands.getRoot().addChild( dummy );