package com.mojang.realmsclient.util.task;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.client.gui.screens.Screen;
import com.mojang.realmsclient.dto.RealmsServerAddress;
import net.minecraft.realms.RealmsConnect;

public class ConnectTask extends LongRunningTask {
    private final RealmsConnect realmsConnect;
    private final RealmsServerAddress address;
    
    public ConnectTask(final Screen dqs, final RealmsServerAddress diq) {
        this.address = diq;
        this.realmsConnect = new RealmsConnect(dqs);
    }
    
    @Override
    public void run() {
        this.setTitle(I18n.get("mco.connect.connecting"));
        final net.minecraft.realms.RealmsServerAddress eqi2 = net.minecraft.realms.RealmsServerAddress.parseString(this.address.address);
        this.realmsConnect.connect(eqi2.getHost(), eqi2.getPort());
    }
    
    @Override
    public void abortTask() {
        this.realmsConnect.abort();
        Minecraft.getInstance().getClientPackSource().clearServerPack();
    }
    
    @Override
    public void tick() {
        this.realmsConnect.tick();
    }
}
