|
6 | 6 | package meteordevelopment.meteorclient.systems.friends;
|
7 | 7 |
|
8 | 8 | import com.mojang.util.UndashedUuid;
|
| 9 | +import meteordevelopment.meteorclient.MeteorClient; |
9 | 10 | import meteordevelopment.meteorclient.utils.misc.ISerializable;
|
| 11 | +import meteordevelopment.meteorclient.utils.network.FailedHttpResponse; |
10 | 12 | import meteordevelopment.meteorclient.utils.network.Http;
|
11 | 13 | import meteordevelopment.meteorclient.utils.render.PlayerHeadTexture;
|
12 | 14 | import meteordevelopment.meteorclient.utils.render.PlayerHeadUtils;
|
|
15 | 17 | import org.jetbrains.annotations.NotNull;
|
16 | 18 |
|
17 | 19 | import javax.annotation.Nullable;
|
| 20 | +import java.net.http.HttpResponse; |
18 | 21 | import java.util.Objects;
|
19 | 22 | import java.util.UUID;
|
20 | 23 |
|
@@ -49,11 +52,32 @@ public PlayerHeadTexture getHead() {
|
49 | 52 |
|
50 | 53 | public void updateInfo() {
|
51 | 54 | updating = true;
|
52 |
| - APIResponse res = Http.get("https://api.mojang.com/users/profiles/minecraft/" + name).sendJson(APIResponse.class); |
53 |
| - if (res == null || res.name == null || res.id == null) return; |
54 |
| - name = res.name; |
55 |
| - id = UndashedUuid.fromStringLenient(res.id); |
56 |
| - mc.execute(() -> headTexture = PlayerHeadUtils.fetchHead(id)); |
| 55 | + HttpResponse<APIResponse> res = null; |
| 56 | + |
| 57 | + if (id != null) { |
| 58 | + res = Http.get("https://sessionserver.mojang.com/session/minecraft/profile/" + UndashedUuid.toString(id)) |
| 59 | + .exceptionHandler(e -> MeteorClient.LOG.error("Error while trying to connect session server for friend '{}'", name)) |
| 60 | + .sendJsonResponse(APIResponse.class); |
| 61 | + } |
| 62 | + |
| 63 | + // Fallback to name-based lookup |
| 64 | + if (res == null || res.statusCode() != 200) { |
| 65 | + res = Http.get("https://api.mojang.com/users/profiles/minecraft/" + name) |
| 66 | + .exceptionHandler(e -> MeteorClient.LOG.error("Error while trying to update info for friend '{}'", name)) |
| 67 | + .sendJsonResponse(APIResponse.class); |
| 68 | + } |
| 69 | + |
| 70 | + if (res != null && res.statusCode() == 200) { |
| 71 | + name = res.body().name; |
| 72 | + id = UndashedUuid.fromStringLenient(res.body().id); |
| 73 | + mc.execute(() -> headTexture = PlayerHeadUtils.fetchHead(id)); |
| 74 | + } |
| 75 | + |
| 76 | + // cracked accounts shouldn't be assigned ids |
| 77 | + else if (!(res instanceof FailedHttpResponse)) { |
| 78 | + id = null; |
| 79 | + } |
| 80 | + |
57 | 81 | updating = false;
|
58 | 82 | }
|
59 | 83 |
|
@@ -91,7 +115,7 @@ public int hashCode() {
|
91 | 115 |
|
92 | 116 | @Override
|
93 | 117 | public int compareTo(@NotNull Friend friend) {
|
94 |
| - return name.compareTo(friend.name); |
| 118 | + return name.compareToIgnoreCase(friend.name); |
95 | 119 | }
|
96 | 120 |
|
97 | 121 | private static class APIResponse {
|
|
0 commit comments