From 26a398be13d6b9d53ee6de926368de8d4fa22310 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Sat, 17 Feb 2024 17:46:22 +0100 Subject: [PATCH 1/2] fix dupe glitch with backpacks --- .../slimefun4/api/player/PlayerProfile.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 00cacd4cd9..8ee380e9f3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -394,12 +394,18 @@ public static boolean get(@Nonnull OfflinePlayer p, @Nonnull Consumer { PlayerData data = Slimefun.getPlayerStorage().loadPlayerData(p.getUniqueId()); - loading.remove(uuid); AsyncProfileLoadEvent event = new AsyncProfileLoadEvent(new PlayerProfile(p, data)); Bukkit.getPluginManager().callEvent(event); Slimefun.getRegistry().getPlayerProfiles().put(uuid, event.getProfile()); + + // Make sure we call this after we actually put the PlayerProfile into the map. + // Otherwise we end up with a race condition where the profile is not in the map just _yet_ + // but the loading flag is gone and we can end up loading it a second time (and thus can dupe items) + // Fixes https://github.com/Slimefun/Slimefun4/issues/4130 + loading.remove(uuid); + callback.accept(event.getProfile()); }); @@ -434,10 +440,15 @@ public static boolean request(@Nonnull OfflinePlayer p) { // Should probably prevent multiple requests for the same profile in the future Slimefun.getThreadService().newThread(Slimefun.instance(), "PlayerProfile#request(" + uuid + ")", () -> { PlayerData data = Slimefun.getPlayerStorage().loadPlayerData(uuid); - loading.remove(uuid); PlayerProfile pp = new PlayerProfile(p, data); Slimefun.getRegistry().getPlayerProfiles().put(uuid, pp); + + // Make sure we call this after we actually put the PlayerProfile into the map. + // Otherwise we end up with a race condition where the profile is not in the map just _yet_ + // but the loading flag is gone and we can end up loading it a second time (and thus can dupe items) + // Fixes https://github.com/Slimefun/Slimefun4/issues/4130 + loading.remove(uuid); }); return false; From c429c161b220f7981b09cc5cfcc5b7bdf711244e Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Sat, 17 Feb 2024 16:56:15 +0000 Subject: [PATCH 2/2] Apply suggestions from code review --- .../slimefun4/api/player/PlayerProfile.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 8ee380e9f3..8dfc7414f8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -400,8 +400,8 @@ public static boolean get(@Nonnull OfflinePlayer p, @Nonnull Consumer