mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-28 13:36:00 +00:00
Properly save PlayerData on json only on 'PlayerEvent.SaveToFile'
This commit is contained in:
1 parent
2c82714f9a
commit
79e20b07db
10 files changed
+57
-35
No files matched your search
@@ -4,7 +4,10 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -86,21 +89,25 @@ public class PlayerDataController {
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
|
||||
private static Executor executor = Executors.newSingleThreadExecutor();
|
||||
public void savePlayerData(PlayerData data){
|
||||
NBTTagCompound compound = data.getNBT();
|
||||
String filename = data.uuid + ".json";
|
||||
try {
|
||||
File saveDir = getSaveDir();
|
||||
File file = new File(saveDir, filename+"_new");
|
||||
File file1 = new File(saveDir, filename);
|
||||
NBTJsonUtil.SaveFile(file, compound);
|
||||
if(file1.exists()){
|
||||
file1.delete();
|
||||
executor.execute(() -> {
|
||||
String filename = data.uuid + ".json";
|
||||
FMLLog.info(String.format("[CustomNPCs] PlayerData Real Saving: %s", data.player.getCommandSenderName()));
|
||||
try {
|
||||
File saveDir = getSaveDir();
|
||||
File file = new File(saveDir, filename+"_new");
|
||||
File file1 = new File(saveDir, filename);
|
||||
NBTJsonUtil.SaveFile(file, compound);
|
||||
if(file1.exists()){
|
||||
file1.delete();
|
||||
}
|
||||
file.renameTo(file1);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
file.renameTo(file1);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public PlayerBankData getBankData(EntityPlayer player, int bankId) {
|
||||
@@ -117,7 +124,7 @@ public class PlayerDataController {
|
||||
if(data == null){
|
||||
player.registerExtendedProperties("CustomNpcsData", data = new PlayerData());
|
||||
data.player = player;
|
||||
data.loadNBTData(null);
|
||||
data.loadPlayerDataFromFile();
|
||||
}
|
||||
data.player = player;
|
||||
return data;
|
||||
|
||||
@@ -49,12 +49,20 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public boolean isGUIOpen = false;
|
||||
|
||||
@Override
|
||||
public void saveNBTData(NBTTagCompound compound) {
|
||||
public void saveNBTData(NBTTagCompound nbtTagCompound) {
|
||||
//Do Nothing
|
||||
}
|
||||
|
||||
public void savePlayerDataOnFile() {
|
||||
PlayerDataController.instance.savePlayerData(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadNBTData(NBTTagCompound compound) {
|
||||
//Do Nothing
|
||||
}
|
||||
|
||||
public void loadPlayerDataFromFile() {
|
||||
NBTTagCompound data = PlayerDataController.instance.loadPlayerData(player.getPersistentID().toString());
|
||||
if(data.hasNoTags()){
|
||||
data = PlayerDataController.instance.loadPlayerDataOld(player.getCommandSenderName());
|
||||
@@ -130,11 +138,11 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
|
||||
public void setGUIOpen(boolean bool) {
|
||||
isGUIOpen = bool;
|
||||
saveNBTData(null);
|
||||
savePlayerDataOnFile();
|
||||
}
|
||||
|
||||
public boolean getGUIOpen() {
|
||||
loadNBTData(null);
|
||||
loadPlayerDataFromFile();
|
||||
return isGUIOpen;
|
||||
}
|
||||
|
||||
@@ -149,7 +157,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
activeCompanion = npc;
|
||||
if(npc != null)
|
||||
((RoleCompanion)npc.roleInterface).companionID = companionID;
|
||||
saveNBTData(null);
|
||||
savePlayerDataOnFile();
|
||||
}
|
||||
|
||||
public void updateCompanion(World world) {
|
||||
|
||||
Reference in new issue
Block a user