From 6829547d3a3a0a47c60ac6de3409a6079dfcc56a Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 30 Jun 2025 21:57:29 -0400 Subject: [PATCH] Copy slot NBT when loading --- .../npcs/controllers/ProfileController.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 20bf56e28..a8f2bf91c 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -110,8 +110,12 @@ public class ProfileController implements IProfileHandler { profile.currentSlotId = 0; saveSlotData(player); } + if (!profile.getSlots().containsKey(profile.currentSlotId)) { + profile.currentSlotId = 0; + } profile.player = player; activeProfiles.put(player.getUniqueID(), profile); + loadSlotData(player); verifySlotQuests(profile.player); save(player, profile); } @@ -147,9 +151,9 @@ public class ProfileController implements IProfileHandler { public synchronized void saveOffline(Profile profile, UUID uuid) { profile.setLocked(true); + final NBTTagCompound compound = profile.writeToNBT(); + final String filename = uuid.toString() + ".dat"; CustomNPCsThreader.customNPCThread.execute(() -> { - final NBTTagCompound compound = profile.writeToNBT(); - final String filename = uuid.toString() + ".dat"; try { File saveDir = getProfileDir(); File fileNew = new File(saveDir, filename + "_new"); @@ -170,9 +174,9 @@ public class ProfileController implements IProfileHandler { public synchronized void save(EntityPlayer player, Profile profile) { profile.setLocked(true); + final NBTTagCompound compound = profile.writeToNBT(); + final String filename = player.getUniqueID() + ".dat"; CustomNPCsThreader.customNPCThread.execute(() -> { - final NBTTagCompound compound = profile.writeToNBT(); - final String filename = player.getUniqueID() + ".dat"; try { File saveDir = getProfileDir(); File fileNew = new File(saveDir, filename + "_new"); @@ -623,7 +627,7 @@ public class ProfileController implements IProfileHandler { for (IProfileData profileData : profileTypes.values()) { NBTTagCompound data; if (slot.getComponents().containsKey(profileData.getTagName())) - data = slot.getComponentData(profileData.getTagName()); + data = (NBTTagCompound) slot.getComponentData(profileData.getTagName()).copy(); else data = new NBTTagCompound(); profileData.setNBT(player, data); @@ -656,7 +660,7 @@ public class ProfileController implements IProfileHandler { ISlot slot = profile.getSlots().get(slotId); for (IProfileData pd : dataList) { if (slot.getComponents().containsKey(pd.getTagName())) { - NBTTagCompound sub = slot.getComponentData(pd.getTagName()); + NBTTagCompound sub = (NBTTagCompound) slot.getComponentData(pd.getTagName()).copy(); List subInfo = pd.getInfo(player, sub); infoList.addAll(subInfo); } @@ -770,6 +774,8 @@ public class ProfileController implements IProfileHandler { NBTTagCompound compound = slot.getComponentData(new CNPCData().getTagName()); if (compound == null) compound = new NBTTagCompound(); + else + compound = (NBTTagCompound) compound.copy(); playerData.setNBT(compound); return playerData; }