From 474576d705a06cb8d5a7060a1fa62ee437a2b9d1 Mon Sep 17 00:00:00 2001 From: DarwinBaker Date: Sat, 18 May 2024 14:37:44 -0400 Subject: [PATCH] Support mojang's new api for getting uuids/names --- AATool/Net/Player.cs | 5 ++++- AATool/Net/Requests/NameRequest.cs | 9 +++++++-- AATool/Net/Requests/UuidRequest.cs | 6 +++++- AATool/Paths.cs | 4 ++-- AATool/Properties/AssemblyInfo.cs | 4 ++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/AATool/Net/Player.cs b/AATool/Net/Player.cs index 45db108..cec763d 100644 --- a/AATool/Net/Player.cs +++ b/AATool/Net/Player.cs @@ -5,6 +5,7 @@ using AATool.Configuration; using AATool.Net.Requests; using Microsoft.Xna.Framework; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace AATool.Net @@ -57,7 +58,9 @@ public static async Task FetchUuidAsync(string name) if (string.IsNullOrEmpty(response)) return Uuid.Empty; - if (Uuid.TryParse(response, out id)) + var values = JsonConvert.DeserializeObject>(response); + + if (Uuid.TryParse(values["id"], out id)) { Cache(id, name); new AvatarRequest(id).EnqueueOnce(); diff --git a/AATool/Net/Requests/NameRequest.cs b/AATool/Net/Requests/NameRequest.cs index 0a9f13f..8371f16 100644 --- a/AATool/Net/Requests/NameRequest.cs +++ b/AATool/Net/Requests/NameRequest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -53,10 +54,14 @@ public override async Task DownloadAsync() private bool HandleResponse(string response) { response = response.Trim(); - if (string.IsNullOrEmpty(response) || response.Contains(" ")) + if (string.IsNullOrEmpty(response)) return false; - Player.Cache(this.id, response); + var values = JsonConvert.DeserializeObject>(response); + + string name = values["name"]; + + Player.Cache(this.id, name); Debug.Log(Debug.RequestSection, $"{Incoming} Received name \"{response}\" for UUID: {this.shortId} in {this.ResponseTime}"); return true; } diff --git a/AATool/Net/Requests/UuidRequest.cs b/AATool/Net/Requests/UuidRequest.cs index 0f0c9a3..92ae2ea 100644 --- a/AATool/Net/Requests/UuidRequest.cs +++ b/AATool/Net/Requests/UuidRequest.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Net.Http; using System.Threading.Tasks; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace AATool.Net.Requests @@ -55,7 +57,9 @@ private bool HandleResponse(string response) if (string.IsNullOrEmpty(response)) return false; - if (Uuid.TryParse(response, out Uuid id)) + var values = JsonConvert.DeserializeObject>(response); + + if (Uuid.TryParse(values["id"], out Uuid id)) { Debug.Log(Debug.RequestSection, $"{Incoming} Received UUID for \"{this.name}\" ({response}) in {this.ResponseTime}"); diff --git a/AATool/Paths.cs b/AATool/Paths.cs index 73517f6..6997506 100644 --- a/AATool/Paths.cs +++ b/AATool/Paths.cs @@ -195,10 +195,10 @@ public static class Web public const string AASsgRecord = "https://www.speedrun.com/api/v1/leaderboards/j1npme6p/category/xk9gz16d?top=1&embed=players&var-38do09zl=5q8rd731&var-r8rg67rn=klrzpjo1"; public static string GetUuidUrl(string name) => - $"https://minecraft-api.com/api/uuid/{name}"; + $"https://api.mojang.com/users/profiles/minecraft/{name}"; public static string GetNameUrl(string uuid) => - $"https://minecraft-api.com/api/pseudo/{uuid.Replace("-", "")}"; + $"https://api.mojang.com/user/profile/{uuid.Replace("-", "")}"; public static string GetAvatarUrlFallback(Uuid uuid, int size) => $"https://crafatar.com/avatars/{uuid}?size={size}&overlay=true"; diff --git a/AATool/Properties/AssemblyInfo.cs b/AATool/Properties/AssemblyInfo.cs index bc947a5..401ebec 100644 --- a/AATool/Properties/AssemblyInfo.cs +++ b/AATool/Properties/AssemblyInfo.cs @@ -33,6 +33,6 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.7.2.1")] -[assembly: AssemblyFileVersion("1.7.2.1")] +[assembly: AssemblyVersion("1.7.2.2")] +[assembly: AssemblyFileVersion("1.7.2.2")] [assembly: NeutralResourcesLanguage("en")]