Merge pull request #173 from KAMKEEL/codex/fix-profile-saving-and-slot-id-issues

Fix profile login save and clarify async behavior
This commit is contained in:
Kam authored and GitHub committed 2025-07-07 05:59:30 -04:00
commit 5fe36cc0c6
3 files changed
+14 -2

No files matched your search

@@ -97,6 +97,7 @@ public class ProfileController implements IProfileHandler {
if (player == null)
return;
Profile profile;
boolean profileModified = false;
if (activeProfiles.containsKey(player.getUniqueID())) {
profile = activeProfiles.get(player.getUniqueID());
profile.player = player;
@@ -109,6 +110,7 @@ public class ProfileController implements IProfileHandler {
profile.getSlots().put(0, defaultSlot);
profile.currentSlotId = 0;
saveSlotData(player);
profileModified = true;
}
if (!profile.getSlots().containsKey(profile.currentSlotId)) {
profile.currentSlotId = 0;
@@ -117,7 +119,10 @@ public class ProfileController implements IProfileHandler {
activeProfiles.put(player.getUniqueID(), profile);
loadSlotData(player);
verifySlotQuests(profile.player);
save(player, profile);
// Avoid saving on every login; only persist if the profile was
// modified (e.g. default slot creation).
if (profileModified)
save(player, profile);
}
}
@@ -341,6 +346,7 @@ public class ProfileController implements IProfileHandler {
return ProfileOperation.error(MSG_CANNOT_CLONE_CURRENT);
}
if (temporary) {
// Use a negative ID for temporary slots so they are never saved to disk.
destinationSlotId = getNextAvailableTempSlot(profile);
} else {
if (destinationSlotId <= 0) {
@@ -81,7 +81,8 @@ public class Profile implements IProfile {
compound.setInteger("CurrentSlotId", currentSlotId);
NBTTagCompound slotsCompound = new NBTTagCompound();
for (Map.Entry<Integer, ISlot> entry : slots.entrySet()) {
// Save only non-temporary slots.
// Temporary slots (typically using negative IDs) are kept in memory
// only and skipped here so they never persist to disk.
if (entry.getValue().isTemporary())
continue;
slotsCompound.setTag(String.valueOf(entry.getKey()), entry.getValue().toNBT());
@@ -4,5 +4,10 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class CustomNPCsThreader {
/**
* Executor used for all asynchronous profile and player data saves.
* It is single-threaded so submitted tasks run sequentially and the
* save order for a given player is preserved.
*/
public static final Executor customNPCThread = Executors.newSingleThreadExecutor();
}