From 0686e5a4e89e748ac6d87bb1ae8f9954dddbaf66 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Mon, 15 Jul 2024 10:08:54 -0500 Subject: [PATCH] Fix duplicate friends being added --- .../worldhost/gui/screen/FriendsScreen.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java index f27edd0..6ef1f67 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java @@ -98,7 +98,7 @@ protected void init() { .build() ); - list.updateEntries(); + list.reloadEntries(); } @Override @@ -133,6 +133,8 @@ public void render( } public class FriendsList extends ObjectSelectionList { + private int reloadCount = 0; + public FriendsList() { super( FriendsScreen.this.minecraft, @@ -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)); + } + })); } } @@ -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); },