Fix profile slot change data overwrite race

This commit is contained in:
Kam committed 2025-10-12 20:31:46 -04:00
1 parent c767c4714d
commit 460a1c5ef9
1 file changed
+13 -8
@@ -518,8 +518,7 @@ public class ProfileController implements IProfileHandler {
if (EventHooks.onProfileChange(handler, scriptPlayer, profile, newSlotId, prevSlot, false))
return ProfileOperation.error(MSG_CANCELLED);
saveSlotData(profile.player);
saveSlotData(profile.player, profile, prevSlot);
profile.currentSlotId = newSlotId;
loadSlotData(profile.player);
@@ -627,17 +626,16 @@ public class ProfileController implements IProfileHandler {
return result;
}
public void saveSlotData(EntityPlayer player) {
if (player == null || !activeProfiles.containsKey(player.getUniqueID()))
private void saveSlotData(EntityPlayer player, Profile profile, int slotId) {
if (player == null || profile == null)
return;
Profile profile = activeProfiles.get(player.getUniqueID());
if (profile.isLocked()) {
return;
}
ISlot slot = profile.getSlots().get(profile.getCurrentSlotId());
ISlot slot = profile.getSlots().get(slotId);
if (slot == null) {
slot = new Slot(profile.getCurrentSlotId(), "Slot " + profile.getCurrentSlotId());
profile.getSlots().put(profile.getCurrentSlotId(), slot);
slot = new Slot(slotId, "Slot " + slotId);
profile.getSlots().put(slotId, slot);
}
for (IProfileData profileData : profileTypes.values()) {
NBTTagCompound cloned = (NBTTagCompound) profileData.getCurrentNBT(player).copy();
@@ -646,6 +644,13 @@ public class ProfileController implements IProfileHandler {
slot.setLastLoaded(System.currentTimeMillis());
}
public void saveSlotData(EntityPlayer player) {
if (player == null || !activeProfiles.containsKey(player.getUniqueID()))
return;
Profile profile = activeProfiles.get(player.getUniqueID());
saveSlotData(player, profile, profile.getCurrentSlotId());
}
public void loadSlotData(EntityPlayer player) {
if (player == null || !activeProfiles.containsKey(player.getUniqueID()))
return;