2020-07-17 18:05:50 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2020-06-27 17:50:15 +02:00
|
|
|
From: tr7zw <tr7zw@live.de>
|
2020-08-03 18:48:42 +02:00
|
|
|
Date: Fri, 31 Jul 2020 22:39:45 -0500
|
|
|
|
Subject: [PATCH] Player-saving-async-FileIO
|
2020-06-27 17:50:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
2020-08-13 17:53:32 +02:00
|
|
|
index ce4ebc96c01f3dacf4e4d0569d86f52140440d43..a52c0391b171c8a57de75f87c534ce1e0e78c44a 100644
|
2020-06-27 17:50:15 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
2020-08-11 20:40:29 +02:00
|
|
|
@@ -700,11 +700,20 @@ public abstract class EntityHuman extends EntityLiving {
|
2020-06-27 17:50:15 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:48:42 +02:00
|
|
|
+ // Yatopia start
|
2020-06-27 17:50:15 +02:00
|
|
|
+ private NBTTagList inventorySnapshot = null;
|
|
|
|
+ private NBTTagList enderchestSnapshot = null;
|
2020-08-13 17:53:32 +02:00
|
|
|
+ public void takeSnapshot() {
|
2020-08-11 20:40:29 +02:00
|
|
|
+ inventorySnapshot = this.inventory.a(new NBTTagList());
|
|
|
|
+ enderchestSnapshot = this.enderChest.g();
|
2020-06-27 17:50:15 +02:00
|
|
|
+ }
|
2020-08-03 18:48:42 +02:00
|
|
|
+ // Yatopia end
|
|
|
|
+
|
2020-06-27 17:50:15 +02:00
|
|
|
@Override
|
|
|
|
public void saveData(NBTTagCompound nbttagcompound) {
|
|
|
|
super.saveData(nbttagcompound);
|
|
|
|
nbttagcompound.setInt("DataVersion", SharedConstants.getGameVersion().getWorldVersion());
|
|
|
|
- nbttagcompound.set("Inventory", this.inventory.a(new NBTTagList()));
|
2020-08-13 17:53:32 +02:00
|
|
|
+ nbttagcompound.set("Inventory", inventorySnapshot != null ? inventorySnapshot : this.inventory.a(new NBTTagList())); inventorySnapshot = null; // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
nbttagcompound.setInt("SelectedItemSlot", this.inventory.itemInHandIndex);
|
|
|
|
nbttagcompound.setShort("SleepTimer", (short) this.sleepTicks);
|
|
|
|
nbttagcompound.setFloat("XpP", this.exp);
|
2020-08-11 20:40:29 +02:00
|
|
|
@@ -714,7 +723,7 @@ public abstract class EntityHuman extends EntityLiving {
|
2020-06-27 17:50:15 +02:00
|
|
|
nbttagcompound.setInt("Score", this.getScore());
|
|
|
|
this.foodData.b(nbttagcompound);
|
|
|
|
this.abilities.a(nbttagcompound);
|
|
|
|
- nbttagcompound.set("EnderItems", this.enderChest.g());
|
2020-08-13 17:53:32 +02:00
|
|
|
+ nbttagcompound.set("EnderItems", enderchestSnapshot != null ? enderchestSnapshot : this.enderChest.g()); enderchestSnapshot = null; // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
if (!this.getShoulderEntityLeft().isEmpty()) {
|
|
|
|
nbttagcompound.set("ShoulderEntityLeft", this.getShoulderEntityLeft());
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-10-02 13:45:30 +02:00
|
|
|
index 5760b40bdbee417f5bb5210f1271241ff8f36350..437698cf4fee266c87eebb8b5f05509b587913e7 100644
|
2020-06-27 17:50:15 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-10-02 13:45:30 +02:00
|
|
|
@@ -1286,6 +1286,18 @@ public abstract class PlayerList {
|
2020-06-27 17:50:15 +02:00
|
|
|
if (team != null) scoreboard.removeTeam(team);
|
|
|
|
}
|
|
|
|
// Paper end
|
2020-08-03 18:48:42 +02:00
|
|
|
+
|
|
|
|
+ // Yatopia start - make sure all saves are done
|
2020-06-27 17:50:15 +02:00
|
|
|
+ try {
|
2020-08-11 20:40:29 +02:00
|
|
|
+ playerFileData.saveThread.shutdown();
|
2020-08-13 17:53:32 +02:00
|
|
|
+ boolean done = playerFileData.saveThread.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
|
+ if (!done) {
|
|
|
|
+ LOGGER.error("Players did not save completely!");
|
|
|
|
+ }
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
2020-08-03 18:48:42 +02:00
|
|
|
+ // Yatopia end
|
2020-06-27 17:50:15 +02:00
|
|
|
}
|
|
|
|
// Paper end
|
|
|
|
|
2020-10-02 13:45:30 +02:00
|
|
|
@@ -1323,13 +1335,13 @@ public abstract class PlayerList {
|
2020-06-27 17:50:15 +02:00
|
|
|
File file = this.server.a(SavedFile.STATS).toFile();
|
|
|
|
File file1 = new File(file, uuid + ".json");
|
|
|
|
|
|
|
|
- if (!file1.exists()) {
|
2020-08-13 17:53:32 +02:00
|
|
|
+ /*if (!file1.exists()) { // Yatopia - don't check for old stats files with sync file IO
|
2020-06-27 17:50:15 +02:00
|
|
|
File file2 = new File(file, displayName + ".json"); // CraftBukkit
|
|
|
|
|
|
|
|
if (file2.exists() && file2.isFile()) {
|
|
|
|
file2.renameTo(file1);
|
|
|
|
}
|
|
|
|
- }
|
2020-08-13 17:53:32 +02:00
|
|
|
+ }*/ // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
|
|
|
|
serverstatisticmanager = new ServerStatisticManager(this.server, file1);
|
|
|
|
// this.o.put(uuid, serverstatisticmanager); // CraftBukkit
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldNBTStorage.java b/src/main/java/net/minecraft/server/WorldNBTStorage.java
|
2020-08-28 11:00:07 +02:00
|
|
|
index a959672f5857b987001252c3fd7ace9e83e07c9b..d8969f7f5244548452e5d12325e6fa735ecd3a00 100644
|
2020-06-27 17:50:15 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldNBTStorage.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldNBTStorage.java
|
2020-08-13 17:53:32 +02:00
|
|
|
@@ -17,6 +17,7 @@ public class WorldNBTStorage {
|
2020-06-27 17:50:15 +02:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
|
|
private final File playerDir;
|
|
|
|
protected final DataFixer a;
|
2020-08-11 20:40:29 +02:00
|
|
|
+ public java.util.concurrent.ExecutorService saveThread = java.util.concurrent.Executors.newSingleThreadExecutor(); // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
|
|
|
|
public WorldNBTStorage(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer) {
|
|
|
|
this.a = datafixer;
|
2020-08-13 17:53:32 +02:00
|
|
|
@@ -26,6 +27,8 @@ public class WorldNBTStorage {
|
2020-08-11 20:40:29 +02:00
|
|
|
|
2020-06-27 17:50:15 +02:00
|
|
|
public void save(EntityHuman entityhuman) {
|
|
|
|
if(!com.destroystokyo.paper.PaperConfig.savePlayerData) return; // Paper - Make player data saving configurable
|
2020-08-13 17:53:32 +02:00
|
|
|
+ entityhuman.takeSnapshot(); // Yatopia
|
2020-08-28 11:00:07 +02:00
|
|
|
+ saveThread.execute(() -> { // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
try {
|
2020-08-11 20:40:29 +02:00
|
|
|
NBTTagCompound nbttagcompound = entityhuman.save(new NBTTagCompound());
|
|
|
|
File file = File.createTempFile(entityhuman.getUniqueIDString() + "-", ".dat", this.playerDir);
|
2020-08-13 17:53:32 +02:00
|
|
|
@@ -38,7 +41,7 @@ public class WorldNBTStorage {
|
2020-06-27 17:50:15 +02:00
|
|
|
} catch (Exception exception) {
|
|
|
|
WorldNBTStorage.LOGGER.error("Failed to save player data for {}", entityhuman.getName(), exception); // Paper
|
|
|
|
}
|
2020-08-13 17:53:32 +02:00
|
|
|
-
|
2020-08-11 20:40:29 +02:00
|
|
|
+ }); // Yatopia
|
|
|
|
}
|
|
|
|
|
2020-08-13 17:53:32 +02:00
|
|
|
@Nullable
|