Fix Load PlayerData for JSON or Dat Types

This commit is contained in:
Kam committed 2023-06-02 03:37:18 -04:00
1 parent e0191ccf89
commit f6b9f2c973
3 files changed
+7 -24

No files matched your search

@@ -25,6 +25,7 @@ import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumPlayerData;
@@ -493,7 +494,11 @@ public class NoppesUtilServer {
playerdata = PlayerDataController.instance.getPlayerData(pl);
if(type == EnumPlayerData.Players){
File file = new File(PlayerDataController.instance.getSaveDir(), playerdata.uuid + ".json");
String fileType = ".json";
if(ConfigMain.DatFormat){
fileType = ".dat";
}
File file = new File(PlayerDataController.instance.getSaveDir(), playerdata.uuid + fileType);
if(file.exists())
file.delete();
if(pl != null){
@@ -279,7 +279,7 @@ public class PlayerDataController {
for(String name : nameUUIDs.keySet()){
if(name.equalsIgnoreCase(username)){
data = new PlayerData();
data.setNBT(PlayerData.loadPlayerData(nameUUIDs.get(name)));
data.setNBT(PlayerDataController.instance.loadPlayerData(nameUUIDs.get(name)));
break;
}
}
@@ -169,28 +169,6 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
world.spawnEntityInWorld(npc);
}
public static NBTTagCompound loadPlayerData(String player) {
File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata");
String filename = player;
if (player.isEmpty()) {
filename = "noplayername";
}
filename = filename + ".json";
File file = null;
try {
file = new File(saveDir, filename);
if (file.exists()) {
return NBTJsonUtil.LoadFile(file);
}
} catch (Exception var5) {
LogWriter.error("Error loading: " + file.getAbsolutePath(), var5);
}
return new NBTTagCompound();
}
public void setCompanion(ICustomNpc npc) {
this.setCompanion((EntityNPCInterface) npc.getMCEntity());
}