Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
import net.minecraft.client.gui.screen.Screen;

import static meteordevelopment.meteorclient.MeteorClient.mc;

public class FriendsTab extends Tab {
public FriendsTab() {
super("Friends");
Expand Down Expand Up @@ -64,7 +66,7 @@ public void initWidgets() {

MeteorExecutor.execute(() -> {
friend.updateInfo();
reload();
mc.execute(this::reload);
});
}
};
Expand All @@ -80,7 +82,6 @@ private void initTable(WTable table) {
MeteorExecutor.execute(() -> {
if (friend.headTextureNeedsUpdate()) {
friend.updateInfo();
reload();
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package meteordevelopment.meteorclient.systems.friends;

import com.mojang.util.UndashedUuid;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.utils.misc.ISerializable;
import meteordevelopment.meteorclient.utils.network.FailedHttpResponse;
import meteordevelopment.meteorclient.utils.network.Http;
import meteordevelopment.meteorclient.utils.render.PlayerHeadTexture;
import meteordevelopment.meteorclient.utils.render.PlayerHeadUtils;
Expand All @@ -15,6 +17,7 @@
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.net.http.HttpResponse;
import java.util.Objects;
import java.util.UUID;

Expand Down Expand Up @@ -49,11 +52,32 @@ public PlayerHeadTexture getHead() {

public void updateInfo() {
updating = true;
APIResponse res = Http.get("https://api.mojang.com/users/profiles/minecraft/" + name).sendJson(APIResponse.class);
if (res == null || res.name == null || res.id == null) return;
name = res.name;
id = UndashedUuid.fromStringLenient(res.id);
mc.execute(() -> headTexture = PlayerHeadUtils.fetchHead(id));
HttpResponse<APIResponse> res = null;

if (id != null) {
res = Http.get("https://sessionserver.mojang.com/session/minecraft/profile/" + UndashedUuid.toString(id))
.exceptionHandler(e -> MeteorClient.LOG.error("Error while trying to connect session server for friend '{}'", name))
.sendJsonResponse(APIResponse.class);
}

// Fallback to name-based lookup
if (res == null || res.statusCode() != 200) {
res = Http.get("https://api.mojang.com/users/profiles/minecraft/" + name)
.exceptionHandler(e -> MeteorClient.LOG.error("Error while trying to update info for friend '{}'", name))
.sendJsonResponse(APIResponse.class);
}

if (res != null && res.statusCode() == 200) {
name = res.body().name;
id = UndashedUuid.fromStringLenient(res.body().id);
mc.execute(() -> headTexture = PlayerHeadUtils.fetchHead(id));
}

// cracked accounts shouldn't be assigned ids
else if (!(res instanceof FailedHttpResponse)) {
id = null;
}

updating = false;
}

Expand Down Expand Up @@ -91,7 +115,7 @@ public int hashCode() {

@Override
public int compareTo(@NotNull Friend friend) {
return name.compareTo(friend.name);
return name.compareToIgnoreCase(friend.name);
}

private static class APIResponse {
Expand Down