package net.minecraft.client.multiplayer;

import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.Component;
import javax.annotation.Nullable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.SharedConstants;

public class ServerData {
    public String name;
    public String ip;
    public String status;
    public String motd;
    public long ping;
    public int protocol;
    public String version;
    public boolean pinged;
    public String playerList;
    private ServerPackStatus packStatus;
    private String iconB64;
    private boolean lan;
    
    public ServerData(final String string1, final String string2, final boolean boolean3) {
        this.protocol = SharedConstants.getCurrentVersion().getProtocolVersion();
        this.version = SharedConstants.getCurrentVersion().getName();
        this.packStatus = ServerPackStatus.PROMPT;
        this.name = string1;
        this.ip = string2;
        this.lan = boolean3;
    }
    
    public CompoundTag write() {
        final CompoundTag jt2 = new CompoundTag();
        jt2.putString("name", this.name);
        jt2.putString("ip", this.ip);
        if (this.iconB64 != null) {
            jt2.putString("icon", this.iconB64);
        }
        if (this.packStatus == ServerPackStatus.ENABLED) {
            jt2.putBoolean("acceptTextures", true);
        }
        else if (this.packStatus == ServerPackStatus.DISABLED) {
            jt2.putBoolean("acceptTextures", false);
        }
        return jt2;
    }
    
    public ServerPackStatus getResourcePackStatus() {
        return this.packStatus;
    }
    
    public void setResourcePackStatus(final ServerPackStatus a) {
        this.packStatus = a;
    }
    
    public static ServerData read(final CompoundTag jt) {
        final ServerData dnu2 = new ServerData(jt.getString("name"), jt.getString("ip"), false);
        if (jt.contains("icon", 8)) {
            dnu2.setIconB64(jt.getString("icon"));
        }
        if (jt.contains("acceptTextures", 1)) {
            if (jt.getBoolean("acceptTextures")) {
                dnu2.setResourcePackStatus(ServerPackStatus.ENABLED);
            }
            else {
                dnu2.setResourcePackStatus(ServerPackStatus.DISABLED);
            }
        }
        else {
            dnu2.setResourcePackStatus(ServerPackStatus.PROMPT);
        }
        return dnu2;
    }
    
    @Nullable
    public String getIconB64() {
        return this.iconB64;
    }
    
    public void setIconB64(@Nullable final String string) {
        this.iconB64 = string;
    }
    
    public boolean isLan() {
        return this.lan;
    }
    
    public void copyFrom(final ServerData dnu) {
        this.ip = dnu.ip;
        this.name = dnu.name;
        this.setResourcePackStatus(dnu.getResourcePackStatus());
        this.iconB64 = dnu.iconB64;
        this.lan = dnu.lan;
    }
    
    public enum ServerPackStatus {
        ENABLED("enabled"), 
        DISABLED("disabled"), 
        PROMPT("prompt");
        
        private final Component name;
        
        private ServerPackStatus(final String string3) {
            this.name = new TranslatableComponent("addServer.resourcePack." + string3, new Object[0]);
        }
        
        public Component getName() {
            return this.name;
        }
    }
}
