Skip to content

Commit

Permalink
fix lag when adding friends
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr7mbl3 authored and arlomcwalter committed Dec 19, 2022
1 parent 6665318 commit 1a32c52
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ private void initTable(WTable table) {
table.clear();
if (Friends.get().isEmpty()) return;

Friends.get().forEach(friend ->
MeteorExecutor.execute(() -> {
if (friend.headTextureNeedsUpdate()) {
friend.updateInfo();
reload();
}
})
);

for (Friend friend : Friends.get()) {
table.add(theme.texture(32, 32, friend.getHead().needsRotate() ? 90 : 0, friend.getHead()));
table.add(theme.label(friend.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import java.util.UUID;

public class Friend implements ISerializable<Friend>, Comparable<Friend> {
public String name;
private @Nullable UUID id;
private @Nullable PlayerHeadTexture headTexture;
public volatile String name;
private volatile @Nullable UUID id;
private volatile @Nullable PlayerHeadTexture headTexture;
private volatile boolean updating;

public Friend(String name, @Nullable UUID id) {
this.name = name;
this.id = id;
this.headTexture = PlayerHeadUtils.fetchHead(id);
this.headTexture = null;
}

public Friend(PlayerEntity player) {
Expand All @@ -45,11 +46,17 @@ 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 = UUIDTypeAdapter.fromString(res.id);
headTexture = PlayerHeadUtils.fetchHead(id);
updating = false;
}

public boolean headTextureNeedsUpdate() {
return !this.updating && headTexture == null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import meteordevelopment.meteorclient.systems.System;
import meteordevelopment.meteorclient.systems.Systems;
import meteordevelopment.meteorclient.utils.misc.NbtUtils;
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
Expand Down Expand Up @@ -126,6 +127,8 @@ public Friends fromTag(NbtCompound tag) {

Collections.sort(friends);

MeteorExecutor.execute(() -> friends.forEach(Friend::updateInfo));

return this;
}
}

0 comments on commit 1a32c52

Please sign in to comment.