Skip to content

Commit

Permalink
Fix duplicate friends being added
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jul 15, 2024
1 parent fb7c541 commit 0686e5a
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void init() {
.build()
);

list.updateEntries();
list.reloadEntries();
}

@Override
Expand Down Expand Up @@ -133,6 +133,8 @@ public void render(
}

public class FriendsList extends ObjectSelectionList<FriendsEntry> {
private int reloadCount = 0;

public FriendsList() {
super(
FriendsScreen.this.minecraft,
Expand All @@ -151,12 +153,15 @@ public void setSelected(@Nullable FriendsEntry entry) {
removeButton.active = entry != null;
}

private void updateEntries() {
private void reloadEntries() {
final int currentReloadCount = reloadCount++;
clearEntries();
for (final var plugin : WorldHost.getPlugins()) {
plugin.plugin().listFriends(friend ->
Minecraft.getInstance().execute(() -> addEntry(new FriendsEntry(friend)))
);
plugin.plugin().listFriends(friend -> Minecraft.getInstance().execute(() -> {
if (reloadCount == currentReloadCount) {
addEntry(new FriendsEntry(friend));
}
}));
}
}

Expand Down Expand Up @@ -210,7 +215,7 @@ public void maybeRemove() {
minecraft.setScreen(new ConfirmScreen(
yes -> {
if (yes) {
friend.removeFriend(() -> minecraft.execute(() -> FriendsScreen.this.list.updateEntries()));
friend.removeFriend(() -> minecraft.execute(() -> FriendsScreen.this.list.reloadEntries()));
}
minecraft.setScreen(FriendsScreen.this);
},
Expand Down

0 comments on commit 0686e5a

Please sign in to comment.