mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 17:44:46 +00:00
Utilize a One Thread and Synchronized attribute to better control data integrity and prevent data loss
This commit is contained in:
1 parent
60dbcc7146
commit
ae1f33d327
6 files changed
+78
-45
No files matched your search
@@ -13,6 +13,7 @@ import net.minecraft.util.IChatComponent;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.util.CustomNPCsScheduler;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
@@ -26,7 +27,6 @@ import java.util.zip.GZIPInputStream;
|
||||
public class PlayerDataController {
|
||||
public static PlayerDataController instance;
|
||||
public HashMap<String, String> nameUUIDs;
|
||||
private static final Executor playerDataThread = Executors.newSingleThreadExecutor();
|
||||
|
||||
public PlayerDataController(){
|
||||
instance = this;
|
||||
@@ -257,13 +257,14 @@ public class PlayerDataController {
|
||||
return new NBTTagCompound();
|
||||
}
|
||||
|
||||
public void savePlayerData(PlayerData data){
|
||||
public synchronized void savePlayerData(PlayerData data){
|
||||
NBTTagCompound compound = data.getNBT();
|
||||
playerDataThread.execute(() -> {
|
||||
String filename = data.uuid + ".json";
|
||||
String filename = data.uuid + ".json";
|
||||
|
||||
CustomNPCsScheduler.runTack(() -> {
|
||||
try {
|
||||
File saveDir = getSaveDir();
|
||||
File file = new File(saveDir, filename+"_new");
|
||||
File file = new File(saveDir, filename + "_new");
|
||||
File file1 = new File(saveDir, filename);
|
||||
NBTJsonUtil.SaveFile(file, compound);
|
||||
if(file1.exists()){
|
||||
|
||||
Reference in new issue
Block a user