Search in sources :

Example 1 with SharedSuggestionProvider

use of net.minecraft.commands.SharedSuggestionProvider in project MinecraftForge by MinecraftForge.

the class VanillaConnectionNetworkFilter method filterCommandList.

/**
 * Filter for SCommandListPacket. Uses {@link CommandTreeCleaner} to filter out any ArgumentTypes that are not in the "minecraft" or "brigadier" namespace.
 * A vanilla client would fail to deserialize the packet and disconnect with an error message if these were sent.
 */
@Nonnull
private static ClientboundCommandsPacket filterCommandList(ClientboundCommandsPacket packet) {
    RootCommandNode<SharedSuggestionProvider> root = packet.getRoot();
    RootCommandNode<SharedSuggestionProvider> newRoot = CommandTreeCleaner.cleanArgumentTypes(root, argType -> {
        ResourceLocation id = ArgumentTypes.getId(argType);
        return id != null && (id.getNamespace().equals("minecraft") || id.getNamespace().equals("brigadier"));
    });
    return new ClientboundCommandsPacket(newRoot);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) ClientboundCommandsPacket(net.minecraft.network.protocol.game.ClientboundCommandsPacket) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)1 SharedSuggestionProvider (net.minecraft.commands.SharedSuggestionProvider)1 ClientboundCommandsPacket (net.minecraft.network.protocol.game.ClientboundCommandsPacket)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1