diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 5ff9d1919..d289c7f33 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -150,22 +150,25 @@ public class ProfileController { // Offline save (synchronous) when no EntityPlayer is available. public static synchronized void saveOffline(Profile profile, UUID uuid) { - final NBTTagCompound compound = profile.writeToNBT(); - final String filename = uuid.toString() + ".dat"; - try { - File saveDir = getProfileDir(); - File fileNew = new File(saveDir, filename + "_new"); - File fileOld = new File(saveDir, filename); - CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew)); - if(fileOld.exists()){ - fileOld.delete(); + profile.locked = true; + 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"); + File fileOld = new File(saveDir, filename); + CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew)); + if(fileOld.exists()){ + fileOld.delete(); + } + fileNew.renameTo(fileOld); + // Also backup if allowed. + backupProfile(uuid, compound); + } catch (Exception e) { + LogWriter.except(e); } - fileNew.renameTo(fileOld); - // Also backup if allowed. - backupProfile(uuid, compound); - } catch (Exception e) { - LogWriter.except(e); - } + }); } // Save for online players (asynchronous). diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index d53ff7c1c..982e5b6f3 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -1,6 +1,8 @@ package noppes.npcs.controllers.data; import kamkeel.npcs.addon.DBCAddon; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; import kamkeel.npcs.network.packets.request.party.PartyInvitePacket; @@ -373,6 +375,13 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { } public synchronized void save() { + // Don't Save this is a Modification of a Profile's PlayerData + Profile profile = ProfileController.getProfile(UUID.fromString(uuid)); + if(profile != null && profile.currentID != this.profileSlot){ + ProfileController.saveOffline(profile, UUID.fromString(uuid)); + return; + } + final NBTTagCompound compound = getNBT(); final String filename; if(ConfigMain.DatFormat){