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

import meteordevelopment.meteorclient.settings.BoolSetting;
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;
import meteordevelopment.meteorclient.utils.player.ChatUtils;

public class HomeSetter
extends Module {
    private final SettingGroup sgGeneral;
    private final Setting<Boolean> chatFeedback;
    private final Setting<Integer> homeSlot;

    public HomeSetter() {
        super(Categories.Donut, "Home setter", "Automatically runs /delhome and /sethome for a selected slot.");
        this.sgGeneral = this.settings.getDefaultGroup();
        this.chatFeedback = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("chat-feedback")).description("Show chat messages when running commands.")).defaultValue(true)).build());
        this.homeSlot = this.sgGeneral.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("home-slot")).description("Which home slot to reset (1-5).")).defaultValue(1)).min(1).max(5).build());
    }

    @Override
    public void onActivate() {
        if (this.mc.field_1724 == null || this.mc.field_1687 == null) {
            return;
        }
        int slot = this.homeSlot.get();
        this.mc.execute(() -> {
            this.sendServerCommand("/delhome " + slot);
            new Thread(() -> {
                try {
                    Thread.sleep(1000L);
                }
                catch (InterruptedException interruptedException) {
                    // empty catch block
                }
                this.mc.execute(() -> {
                    this.sendServerCommand("/sethome " + slot);
                    if (this.chatFeedback.get().booleanValue()) {
                        this.info("Home " + slot + " deleted and set successfully!", new Object[0]);
                    }
                    this.toggle();
                });
            }, "HomeSetter-DelayThread").start();
        });
    }

    private void sendServerCommand(String command) {
        ChatUtils.sendPlayerMsg(command);
    }
}

