Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dupe glitch with backpacks #4134

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,18 @@ public static boolean get(@Nonnull OfflinePlayer p, @Nonnull Consumer<PlayerProf
loading.put(uuid, true);
Slimefun.getThreadService().newThread(Slimefun.instance(), "PlayerProfile#get(" + uuid + ")", () -> {
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.
WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
// Otherwise we end up with a race condition where the profile is not in the map just _yet_
WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
// 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());
});

Expand Down Expand Up @@ -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.
WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
// Otherwise we end up with a race condition where the profile is not in the map just _yet_
WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
// 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;
Expand Down
Loading