package com.example.addon.modules;

import com.example.addon.LauncherManger;
import com.example.addon.launcher;
import it.unimi.dsi.fastutil.objects.ObjectObjectImmutablePair;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.ServerConnectBeginEvent;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.settings.StringSetting;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.client.input.Input;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.util.math.Vec3d;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.example.addon.AddonTemplate.CATEGORY;


public class ModuleExample extends Module {
    ServerAddress current_addr;


    LauncherManger lm;
    public ModuleExample(LauncherManger lm) {
        super(CATEGORY, "Meteor-Bot", "An example module in a custom category.");
        MeteorClient.EVENT_BUS.subscribe(new StaticListener());

        this.lm = lm;
    }

    private final SettingGroup sgGeneral = settings.getDefaultGroup();

    private final Setting<String> botpath = sgGeneral.add(new StringSetting.Builder()
        .name("Path")
        .description("The location of the bot .minecraft folder")
        .defaultValue("/home/astatin3/GitHub/meteorbot/instance")
        .visible(() -> true)
        .build()
    );

    private final Setting<Boolean> verboseMode = sgGeneral.add(new BoolSetting.Builder()
        .name("Verbose")
        .description("Enable verbose output")
        .defaultValue(true)
        .visible(() -> true)
        .build()
    );

    public void onActivate() {
//        test = new launcher(botpath.get(), "bot", 0, current_addr);
//        test.start();
        lm.start(botpath.get(), 8, "bot", current_addr);
    }

    @Override
    public void onDeactivate() {
        if(lm.running())
            lm.stop();
    }

    private class StaticListener {
        @EventHandler
        private void onGameJoined(ServerConnectBeginEvent event) {
            current_addr = event.address;
        }
    }

}
