/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.mojang.brigadier.arguments.StringArgumentType
 *  com.mojang.brigadier.builder.LiteralArgumentBuilder
 *  net.minecraft.class_2172
 *  net.minecraft.class_2596
 *  net.minecraft.class_2797
 *  net.minecraft.class_3515$class_7426
 *  net.minecraft.class_634
 *  net.minecraft.class_7469
 *  net.minecraft.class_7608
 *  net.minecraft.class_7637$class_7816
 *  org.meteordev.starscript.Script
 */
package meteordevelopment.meteorclient.commands.commands;

import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import java.time.Instant;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.mixin.ClientPlayNetworkHandlerAccessor;
import meteordevelopment.meteorclient.utils.misc.MeteorStarscript;
import net.minecraft.class_2172;
import net.minecraft.class_2596;
import net.minecraft.class_2797;
import net.minecraft.class_3515;
import net.minecraft.class_634;
import net.minecraft.class_7469;
import net.minecraft.class_7608;
import net.minecraft.class_7637;
import org.meteordev.starscript.Script;

public class SayCommand
extends Command {
    public SayCommand() {
        super("say", "Sends messages in chat.", new String[0]);
    }

    @Override
    public void build(LiteralArgumentBuilder<class_2172> builder) {
        builder.then(SayCommand.argument("message", StringArgumentType.greedyString()).executes(context -> {
            String message;
            String msg = (String)context.getArgument("message", String.class);
            Script script = MeteorStarscript.compile(msg);
            if (script != null && (message = MeteorStarscript.run(script)) != null) {
                Instant instant = Instant.now();
                long l = class_3515.class_7426.method_43531();
                class_634 handler = mc.method_1562();
                class_7637.class_7816 lastSeenMessages = ((ClientPlayNetworkHandlerAccessor)handler).meteor$getLastSeenMessagesCollector().method_46266();
                class_7469 messageSignatureData = ((ClientPlayNetworkHandlerAccessor)handler).meteor$getMessagePacker().pack(new class_7608(message, instant, l, lastSeenMessages.comp_1073()));
                handler.method_52787((class_2596)new class_2797(message, instant, l, messageSignatureData, lastSeenMessages.comp_1074()));
            }
            return 1;
        }));
    }
}

