Update User.cs

Спасибо Mih4n за код-ревью
This commit is contained in:
Dima YaFlay
2023-10-16 19:02:04 +03:00
committed by GitHub
parent bbbce953e0
commit 76394247ae

View File

@@ -4,20 +4,22 @@ namespace spworlds.Types;
public class User public class User
{ {
private string Name { get; } public readonly string Name
public readonly string Uuid
public readonly JsonNode profile
private HttpClient client = new(); private HttpClient client = new();
private string nonSerializedUuid = await client.GetStringAsync($"https://api.mojang.com/users/profiles/minecraft/{Name}");
private JsonNode uuid = JsonNode.Parse(nonSerializedUuid); public bool IsPlayer() => this.Name != null ? true : false;
private string Uuid { get; } = uuid["id"]
string nonSerializedProfileId = await client.GetStringAsync($"https://sessionserver.mojang.com/session/minecraft/profile/{Uuid}"); public User()
private JsonNode profile = JsonNode.Parse(nonSerializedProfileId); {
Uuid = JsonNode.Parse(await client.GetStringAsync($"https://api.mojang.com/users/profiles/minecraft/{Name}"))["id"];
profile = JsonNode.Parse(await client.GetStringAsync($"https://sessionserver.mojang.com/session/minecraft/profile/{Uuid}"));
}
public async Task<string> GetSkinPart(SkinPart skinPart, string size) public async Task<string> GetSkinPart(SkinPart skinPart, string size = "64")
{ {
return (string)$"https://visage.surgeplay.com/{skinPart}/{size}/{this.profile["profileId"]}" return (string)$"https://visage.surgeplay.com/{skinPart}/{size}/{this.profile["profileId"]}"
} }
public string GetName() => this.Name; }
public string GetUuid() => this.Uuid;
public JsonNode GetProfile() => return this.profile;
public bool IsPlayer() => this.Name != null : false;
}