package net.minecraft.client; import com.mojang.util.UndashedUuid; import java.util.Arrays; import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.UUID; import java.util.function.Function; import java.util.stream.Collectors; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) public class User { private final String name; private final UUID uuid; private final String accessToken; private final Optional xuid; private final Optional clientId; private final User.Type type; public User(String name, UUID uuid, String accessToken, Optional xuid, Optional clientId, User.Type type) { this.name = name; this.uuid = uuid; this.accessToken = accessToken; this.xuid = xuid; this.clientId = clientId; this.type = type; } public String getSessionId() { return "token:" + this.accessToken + ":" + UndashedUuid.toString(this.uuid); } public UUID getProfileId() { return this.uuid; } public String getName() { return this.name; } public String getAccessToken() { return this.accessToken; } public Optional getClientId() { return this.clientId; } public Optional getXuid() { return this.xuid; } public User.Type getType() { return this.type; } @Environment(EnvType.CLIENT) public static enum Type { LEGACY("legacy"), MOJANG("mojang"), MSA("msa"); private static final Map BY_NAME = (Map)Arrays.stream(values()) .collect(Collectors.toMap(type -> type.name, Function.identity())); private final String name; private Type(final String name) { this.name = name; } @Nullable public static User.Type byName(String typeName) { return (User.Type)BY_NAME.get(typeName.toLowerCase(Locale.ROOT)); } public String getName() { return this.name; } } }