package com.example.addon.commands;

import com.example.addon.AddonTemplate;
import com.example.addon.LauncherManger;
import com.example.addon.modules.ModuleExample;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import meteordevelopment.meteorclient.commands.Command;
import net.minecraft.command.CommandSource;

import static com.mojang.brigadier.Command.SINGLE_SUCCESS;

/**
 * The Meteor Client command API uses the <a href="https://github.com/Mojang/brigadier">same command system as Minecraft does</a>.
 */
public class CommandExample extends Command {
    LauncherManger lm;
    public CommandExample(LauncherManger lm) {
        super("bot", "Sends a message.");
        this.lm = lm;
    }

    @Override
    public void build(LiteralArgumentBuilder<CommandSource> builder) {
        builder.executes(context -> {
            info("hi");
            return SINGLE_SUCCESS;
        });

        builder.then(literal("name").then(argument("nameArgument", StringArgumentType.greedyString()).executes(context -> {
            String argument = StringArgumentType.getString(context, "nameArgument");
            if(!lm.running()){
                info("The bot has not been initilized yet.");
                return SINGLE_SUCCESS;
            }

            for(int i = 0; i < lm.launcherList.size(); i++){
                lm.launcherList.get(i).mcinput.println(argument);
            }

            return SINGLE_SUCCESS;
        })));
    }
}
