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
private HttpClient client = new(); public readonly string Uuid
private string nonSerializedUuid = await client.GetStringAsync($"https://api.mojang.com/users/profiles/minecraft/{Name}"); public readonly JsonNode profile
private JsonNode uuid = JsonNode.Parse(nonSerializedUuid);
private string Uuid { get; } = uuid["id"]
string nonSerializedProfileId = await client.GetStringAsync($"https://sessionserver.mojang.com/session/minecraft/profile/{Uuid}");
private JsonNode profile = JsonNode.Parse(nonSerializedProfileId);
public async Task<string> GetSkinPart(SkinPart skinPart, string size) private HttpClient client = new();
public bool IsPlayer() => this.Name != null ? true : false;
public User()
{
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 = "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;
} }