Added PlayerData .dat Format for Faster Server Optimization/Saving

This commit is contained in:
Kam committed 2023-06-02 02:09:38 -04:00
1 parent 0006526c32
commit acd70b13df
3 files changed
+225 -66

No files matched your search

@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
@@ -10,6 +11,7 @@ import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.handler.*;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.entity.EntityCustomNpc;
@@ -22,6 +24,7 @@ import noppes.npcs.util.CustomNPCsThreader;
import noppes.npcs.util.NBTJsonUtil;
import java.io.File;
import java.io.FileOutputStream;
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public PlayerDialogData dialogData = new PlayerDialogData(this);
@@ -230,13 +233,22 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public synchronized void save() {
final NBTTagCompound compound = getNBT();
final String filename = uuid + ".json";
final String filename;
if(ConfigMain.DatFormat){
filename = uuid + ".json";
} else {
filename = uuid + ".dat";
}
CustomNPCsThreader.playerDataThread.execute(() -> {
try {
File saveDir = PlayerDataController.instance.getSaveDir();
File file = new File(saveDir, filename + "_new");
File file1 = new File(saveDir, filename);
NBTJsonUtil.SaveFile(file, compound);
if(ConfigMain.DatFormat){
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(file));
} else {
NBTJsonUtil.SaveFile(file, compound);
}
if(file1.exists()){
file1.delete();
}