package com.mojang.realmsclient.util.task;

import com.mojang.realmsclient.exception.RetryCallException;
import net.minecraft.client.resources.language.I18n;
import com.mojang.realmsclient.client.RealmsClient;

public class SwitchSlotTask extends LongRunningTask {
    private final long worldId;
    private final int slot;
    private final Runnable callback;
    
    public SwitchSlotTask(final long long1, final int integer, final Runnable runnable) {
        this.worldId = long1;
        this.slot = integer;
        this.callback = runnable;
    }
    
    @Override
    public void run() {
        final RealmsClient dia2 = RealmsClient.create();
        final String string3 = I18n.get("mco.minigame.world.slot.screen.title");
        this.setTitle(string3);
        for (int integer4 = 0; integer4 < 25; ++integer4) {
            try {
                if (this.aborted()) {
                    return;
                }
                if (dia2.switchSlot(this.worldId, this.slot)) {
                    this.callback.run();
                    break;
                }
            }
            catch (RetryCallException dji5) {
                if (this.aborted()) {
                    return;
                }
                LongRunningTask.pause(dji5.delaySeconds);
            }
            catch (Exception exception5) {
                if (this.aborted()) {
                    return;
                }
                SwitchSlotTask.LOGGER.error("Couldn't switch world!");
                this.error(exception5.toString());
            }
        }
    }
}
