mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-22 08:29:28 +00:00
Add timeout to AsyncPlayerDataSaving (#275)
* Add timeout to AsyncPlayerDataSaving * dump thread if failed to save playerdata * PlayerDataStorage#lockFor break loop after cancel
This commit is contained in:
@@ -5,7 +5,7 @@ Subject: [PATCH] Async playerdata saving
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
||||
index f2d87c12dd19210ce7e2147fada5c10191008632..0cc6b6c597ca8c955b246764de637be4c25bfb40 100644
|
||||
index f2d87c12dd19210ce7e2147fada5c10191008632..bd6608787abcd1869f66d67297c6b4252193080a 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
||||
@@ -207,7 +207,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
@@ -17,34 +17,23 @@ index f2d87c12dd19210ce7e2147fada5c10191008632..0cc6b6c597ca8c955b246764de637be4
|
||||
}
|
||||
|
||||
private CompoundTag getBukkitData() {
|
||||
@@ -813,6 +813,17 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
@@ -813,16 +813,9 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
* @param compoundTag
|
||||
*/
|
||||
private void save(CompoundTag compoundTag) {
|
||||
- File playerDir = server.console.playerDataStorage.getPlayerDir();
|
||||
- try {
|
||||
- File tempFile = File.createTempFile(this.getUniqueId()+"-", ".dat", playerDir);
|
||||
- net.minecraft.nbt.NbtIo.writeCompressed(compoundTag, tempFile.toPath());
|
||||
- File playerDataFile = new File(playerDir, this.getUniqueId()+".dat");
|
||||
- File playerDataFileOld = new File(playerDir, this.getUniqueId()+".dat_old");
|
||||
- net.minecraft.Util.safeReplaceFile(playerDataFile.toPath(), tempFile.toPath(), playerDataFileOld.toPath());
|
||||
- } catch (java.io.IOException e) {
|
||||
- e.printStackTrace();
|
||||
- }
|
||||
+ // Leaf start - Async playerdata saving
|
||||
+ synchronized (server.console.playerDataStorage) {
|
||||
+ while (server.console.playerDataStorage.savingQueue.contains(getUniqueId())) {
|
||||
+ try {
|
||||
+ Thread.sleep(1L);
|
||||
+ } catch (InterruptedException ignored) {
|
||||
+ }
|
||||
+ }
|
||||
+ server.console.playerDataStorage.savingQueue.add(getUniqueId());
|
||||
+ }
|
||||
+ // Leaf end - Async playerdata saving
|
||||
File playerDir = server.console.playerDataStorage.getPlayerDir();
|
||||
try {
|
||||
File tempFile = File.createTempFile(this.getUniqueId()+"-", ".dat", playerDir);
|
||||
@@ -822,6 +833,12 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
||||
net.minecraft.Util.safeReplaceFile(playerDataFile.toPath(), tempFile.toPath(), playerDataFileOld.toPath());
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
+ // Leaf start - Async playerdata saving
|
||||
+ } finally {
|
||||
+ synchronized (server.console.playerDataStorage) {
|
||||
+ server.console.playerDataStorage.savingQueue.remove(getUniqueId());
|
||||
+ }
|
||||
+ // Leaf end - Async playerdata saving
|
||||
}
|
||||
+ server.console.playerDataStorage.save(this.getName(), this.getUniqueId(), this.getUniqueId().toString(), compoundTag);
|
||||
+ // Leaf end
|
||||
}
|
||||
// Purpur end - OfflinePlayer API
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user