package com.mojang.realmsclient.util.task;

import com.mojang.realmsclient.exception.RetryCallException;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.language.I18n;
import com.mojang.realmsclient.client.RealmsClient;
import com.mojang.realmsclient.gui.screens.RealmsConfigureWorldScreen;
import com.mojang.realmsclient.dto.WorldTemplate;

public class SwitchMinigameTask extends LongRunningTask {
    private final long worldId;
    private final WorldTemplate worldTemplate;
    private final RealmsConfigureWorldScreen lastScreen;
    
    public SwitchMinigameTask(final long long1, final WorldTemplate djd, final RealmsConfigureWorldScreen djr) {
        this.worldId = long1;
        this.worldTemplate = djd;
        this.lastScreen = djr;
    }
    
    @Override
    public void run() {
        final RealmsClient dia2 = RealmsClient.create();
        final String string3 = I18n.get("mco.minigame.world.starting.screen.title");
        this.setTitle(string3);
        for (int integer4 = 0; integer4 < 25; ++integer4) {
            try {
                if (this.aborted()) {
                    return;
                }
                if (dia2.putIntoMinigameMode(this.worldId, this.worldTemplate.id)) {
                    LongRunningTask.setScreen(this.lastScreen);
                    break;
                }
            }
            catch (RetryCallException dji5) {
                if (this.aborted()) {
                    return;
                }
                LongRunningTask.pause(dji5.delaySeconds);
            }
            catch (Exception exception5) {
                if (this.aborted()) {
                    return;
                }
                SwitchMinigameTask.LOGGER.error("Couldn't start mini game!");
                this.error(exception5.toString());
            }
        }
    }
}
