/*
 * Decompiled with CFR 0.152.
 */
package meteordevelopment.meteorclient.systems.modules.donut;

import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;

public class HomeSet
extends Module {
    private final SettingGroup sgGeneral;
    private final Setting<Integer> homeSlot;
    private final Setting<Integer> delayMs;
    private boolean running;

    public HomeSet() {
        super(Categories.Donut, "home-set", "Runs /delhome and /sethome for a selected slot.");
        this.sgGeneral = this.settings.getDefaultGroup();
        this.homeSlot = this.sgGeneral.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("home-slot")).description("The home slot to delete and set.")).defaultValue(1)).min(1).max(10).build());
        this.delayMs = this.sgGeneral.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("delay-ms")).description("The delay between deleting and setting the home in milliseconds.")).defaultValue(750)).min(100).max(5000).build());
        this.running = false;
    }

    @Override
    public void onActivate() {
        if (this.running) {
            return;
        }
        if (this.mc.field_1724 == null) {
            this.toggle();
            return;
        }
        this.running = true;
        int slot = this.homeSlot.get();
        int wait = this.delayMs.get();
        this.mc.field_1724.field_3944.method_45730("delhome " + slot);
        new Thread(() -> {
            try {
                Thread.sleep(wait);
            }
            catch (InterruptedException interruptedException) {
                // empty catch block
            }
            this.mc.execute(() -> {
                if (this.mc.field_1724 != null) {
                    this.mc.field_1724.field_3944.method_45730("sethome " + slot);
                    this.info("Home " + slot + " deleted and set successfully!", new Object[0]);
                }
                this.running = false;
                this.toggle();
            });
        }, "HomeSet-Thread").start();
    }

    @Override
    public void onDeactivate() {
        this.running = false;
    }
}

