From 76394247aefbddf03a7044ff7320151ed76c19d0 Mon Sep 17 00:00:00 2001 From: Dima YaFlay <93622229+YaFlay@users.noreply.github.com> Date: Mon, 16 Oct 2023 19:02:04 +0300 Subject: [PATCH] Update User.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Спасибо Mih4n за код-ревью --- src/Types/User.cs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Types/User.cs b/src/Types/User.cs index 0b97abd..dfa06ff 100644 --- a/src/Types/User.cs +++ b/src/Types/User.cs @@ -4,20 +4,22 @@ namespace spworlds.Types; public class User { - private string Name { get; } + public readonly string Name + public readonly string Uuid + public readonly JsonNode profile + private HttpClient client = new(); - private string nonSerializedUuid = await client.GetStringAsync($"https://api.mojang.com/users/profiles/minecraft/{Name}"); - 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 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 GetSkinPart(SkinPart skinPart, string size) + public async Task GetSkinPart(SkinPart skinPart, string size = "64") { 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; -} \ No newline at end of file +}