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/AdvancementDataPlayer.java b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
|
2020-08-28 11:00:07 +02:00
|
|
|
index cf539c98073b475eb5b769c8cc11d48a7e6d58f1..20b97d1e68132a9f1b62dece5c26da80e67347b7 100644
|
2020-06-27 17:50:15 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java
|
2020-08-11 20:40:29 +02:00
|
|
|
@@ -50,6 +50,7 @@ public class AdvancementDataPlayer {
|
2020-06-27 17:50:15 +02:00
|
|
|
@Nullable
|
|
|
|
private Advancement l;
|
|
|
|
private boolean m = true;
|
2020-08-11 20:40:29 +02:00
|
|
|
+ public static java.util.concurrent.ExecutorService saveThread = java.util.concurrent.Executors.newSingleThreadExecutor(); // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
|
2020-07-25 17:16:49 +02:00
|
|
|
// Paper start - fix advancement data player leakage
|
2020-07-16 22:05:14 +02:00
|
|
|
final Map<CriterionTriggerAbstract, Set<CriterionTrigger.a>> criterionData = Maps.newIdentityHashMap();
|
2020-08-11 20:40:29 +02:00
|
|
|
@@ -228,6 +229,15 @@ public class AdvancementDataPlayer {
|
2020-06-27 17:50:15 +02:00
|
|
|
|
|
|
|
jsonelement.getAsJsonObject().addProperty("DataVersion", SharedConstants.getGameVersion().getWorldVersion());
|
|
|
|
|
2020-08-11 20:40:29 +02:00
|
|
|
+ // Yatopia start - replace whole logic
|
2020-08-28 11:00:07 +02:00
|
|
|
+ saveThread.execute(() -> {
|
2020-08-11 20:40:29 +02:00
|
|
|
+ try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f), Charsets.UTF_8.newEncoder())) {
|
|
|
|
+ AdvancementDataPlayer.b.toJson(jsonelement, writer);
|
|
|
|
+ } catch (Throwable e) {
|
|
|
|
+ AdvancementDataPlayer.LOGGER.error("Couldn't save player advancements to {}", this.f, e);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ /*
|
2020-06-27 17:50:15 +02:00
|
|
|
try {
|
2020-08-11 20:40:29 +02:00
|
|
|
FileOutputStream fileoutputstream = new FileOutputStream(this.f);
|
|
|
|
Throwable throwable = null;
|
2020-08-13 17:53:32 +02:00
|
|
|
@@ -275,7 +285,7 @@ public class AdvancementDataPlayer {
|
2020-08-11 20:40:29 +02:00
|
|
|
} catch (IOException ioexception) {
|
|
|
|
AdvancementDataPlayer.LOGGER.error("Couldn't save player advancements to {}", this.f, ioexception);
|
2020-06-27 17:50:15 +02:00
|
|
|
}
|
2020-08-13 17:53:32 +02:00
|
|
|
-
|
|
|
|
+ */ // Yatopia end
|
2020-06-27 17:50:15 +02:00
|
|
|
}
|
|
|
|
|
2020-08-13 17:53:32 +02:00
|
|
|
public boolean grantCriteria(Advancement advancement, String s) {
|
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-08-31 11:24:45 +02:00
|
|
|
index 334fd6fe58f53ad8989ac4ddf523b156a8dd264d..8bec2ac5e78f28e879db69e1673b0cd90f5abc31 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-08-31 11:24:45 +02:00
|
|
|
@@ -1283,6 +1283,28 @@ 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!");
|
|
|
|
+ }
|
|
|
|
+ ServerStatisticManager.saveThread.shutdown();
|
|
|
|
+ done = ServerStatisticManager.saveThread.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
|
+ if (!done) {
|
|
|
|
+ LOGGER.error("Stats did not save completely!");
|
|
|
|
+ }
|
|
|
|
+ AdvancementDataPlayer.saveThread.shutdown();
|
|
|
|
+ done = AdvancementDataPlayer.saveThread.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
|
+ if (!done) {
|
|
|
|
+ LOGGER.error("Advancements 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-08-31 11:24:45 +02:00
|
|
|
@@ -1320,13 +1342,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/ServerStatisticManager.java b/src/main/java/net/minecraft/server/ServerStatisticManager.java
|
2020-08-28 11:00:07 +02:00
|
|
|
index 3c3b87e37cbf69c223da007e8b7eb646ec83691e..ef20b3e43eb9598e79ee3ded40f50ae0cc100872 100644
|
2020-06-27 17:50:15 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/ServerStatisticManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ServerStatisticManager.java
|
2020-08-13 17:53:32 +02:00
|
|
|
@@ -30,6 +30,7 @@ public class ServerStatisticManager extends StatisticManager {
|
2020-06-27 17:50:15 +02:00
|
|
|
private final File d;
|
|
|
|
private final Set<Statistic<?>> e = Sets.newHashSet();
|
|
|
|
private int f = -300;
|
2020-08-11 20:40:29 +02:00
|
|
|
+ public static java.util.concurrent.ExecutorService saveThread = java.util.concurrent.Executors.newSingleThreadExecutor(); // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
|
|
|
|
public ServerStatisticManager(MinecraftServer minecraftserver, File file) {
|
|
|
|
this.c = minecraftserver;
|
2020-08-13 17:53:32 +02:00
|
|
|
@@ -41,6 +42,7 @@ public class ServerStatisticManager extends StatisticManager {
|
2020-06-27 17:50:15 +02:00
|
|
|
this.a.put( wrapper, entry.getValue().intValue() );
|
|
|
|
}
|
2020-08-11 20:40:29 +02:00
|
|
|
// Spigot end
|
2020-08-28 11:00:07 +02:00
|
|
|
+ saveThread.execute(() -> { // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
if (file.isFile()) {
|
|
|
|
try {
|
|
|
|
this.a(minecraftserver.getDataFixer(), org.apache.commons.io.FileUtils.readFileToString(file));
|
2020-08-13 17:53:32 +02:00
|
|
|
@@ -50,17 +52,20 @@ public class ServerStatisticManager extends StatisticManager {
|
2020-06-27 17:50:15 +02:00
|
|
|
ServerStatisticManager.LOGGER.error("Couldn't parse statistics file {}", file, jsonparseexception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-
|
2020-08-11 20:40:29 +02:00
|
|
|
+ }); // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot
|
2020-08-03 18:48:42 +02:00
|
|
|
+ // Yatopia start
|
2020-06-27 17:50:15 +02:00
|
|
|
+ String str = this.b();
|
2020-08-28 11:00:07 +02:00
|
|
|
+ saveThread.execute(() -> {
|
2020-06-27 17:50:15 +02:00
|
|
|
try {
|
|
|
|
- org.apache.commons.io.FileUtils.writeStringToFile(this.d, this.b());
|
|
|
|
+ org.apache.commons.io.FileUtils.writeStringToFile(this.d, str);
|
|
|
|
} catch (IOException ioexception) {
|
|
|
|
ServerStatisticManager.LOGGER.error("Couldn't save stats", ioexception);
|
|
|
|
}
|
|
|
|
-
|
2020-08-13 17:53:32 +02:00
|
|
|
+ }); // Yatopia end
|
2020-06-27 17:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-13 17:53:32 +02:00
|
|
|
@@ -111,7 +116,7 @@ public class ServerStatisticManager extends StatisticManager {
|
2020-06-27 17:50:15 +02:00
|
|
|
|
|
|
|
if (nbttagcompound2.hasKeyOfType(s2, 99)) {
|
|
|
|
SystemUtils.a(this.a(statisticwrapper, s2), (statistic) -> {
|
|
|
|
- this.a.put(statistic, nbttagcompound2.getInt(s2));
|
2020-08-13 17:53:32 +02:00
|
|
|
+ this.a.put(statistic, nbttagcompound2.getInt(s2) + this.a.getOrDefault(statistic, 0)); // Yatopia
|
2020-06-27 17:50:15 +02:00
|
|
|
}, () -> {
|
|
|
|
ServerStatisticManager.LOGGER.warn("Invalid statistic in {}: Don't know what {} is", this.d, s2);
|
|
|
|
});
|
|
|
|
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
|