From 1a32c528d5dd43266fce167505c0c530715a46fc Mon Sep 17 00:00:00 2001 From: Cr7mbl3 <24521103+Cr7mbl3@users.noreply.github.com> Date: Mon, 19 Dec 2022 06:58:48 +0100 Subject: [PATCH] fix lag when adding friends --- .../meteorclient/gui/tabs/builtin/FriendsTab.java | 9 +++++++++ .../meteorclient/systems/friends/Friend.java | 15 +++++++++++---- .../meteorclient/systems/friends/Friends.java | 3 +++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/FriendsTab.java b/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/FriendsTab.java index c326c98a66..b5c1c305ec 100644 --- a/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/FriendsTab.java +++ b/src/main/java/meteordevelopment/meteorclient/gui/tabs/builtin/FriendsTab.java @@ -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())); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/friends/Friend.java b/src/main/java/meteordevelopment/meteorclient/systems/friends/Friend.java index e8f591f7e0..5b6187301f 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/friends/Friend.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/friends/Friend.java @@ -19,14 +19,15 @@ import java.util.UUID; public class Friend implements ISerializable, Comparable { - 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) { @@ -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 diff --git a/src/main/java/meteordevelopment/meteorclient/systems/friends/Friends.java b/src/main/java/meteordevelopment/meteorclient/systems/friends/Friends.java index 065b464739..3bd7768469 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/friends/Friends.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/friends/Friends.java @@ -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; @@ -126,6 +127,8 @@ public Friends fromTag(NbtCompound tag) { Collections.sort(friends); + MeteorExecutor.execute(() -> friends.forEach(Friend::updateInfo)); + return this; } }