Skip to content

Commit

Permalink
Support mojang's new api for getting uuids/names
Browse files Browse the repository at this point in the history
  • Loading branch information
DarwinBaker committed May 18, 2024
1 parent 42307cc commit 474576d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion AATool/Net/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +58,9 @@ public static async Task<Uuid> FetchUuidAsync(string name)
if (string.IsNullOrEmpty(response))
return Uuid.Empty;

if (Uuid.TryParse(response, out id))
var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(response);

if (Uuid.TryParse(values["id"], out id))
{
Cache(id, name);
new AvatarRequest(id).EnqueueOnce();
Expand Down
9 changes: 7 additions & 2 deletions AATool/Net/Requests/NameRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
Expand Down Expand Up @@ -53,10 +54,14 @@ public override async Task<bool> 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<Dictionary<string, string>>(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;
}
Expand Down
6 changes: 5 additions & 1 deletion AATool/Net/Requests/UuidRequest.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<Dictionary<string, string>>(response);

if (Uuid.TryParse(values["id"], out Uuid id))
{
Debug.Log(Debug.RequestSection, $"{Incoming} Received UUID for \"{this.name}\" ({response}) in {this.ResponseTime}");

Expand Down
4 changes: 2 additions & 2 deletions AATool/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions AATool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit 474576d

Please sign in to comment.