9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-23 00:49:31 +00:00
Files
Leaf/leaf-server/paper-patches/features/0033-Async-playerdata-saving.patch
hayanesuru 107ae7954f async saving player stats and advancements (#334)
* async saving player stats and advancements

* remove thread check

* fix interrupt

* longer wait IO tasks time

* safe replace

* delay join while saving player

* mark as experimental

---------

Co-authored-by: Taiyou06 <kaandindar21@gmail.com>
2025-06-08 12:18:01 +09:00

38 lines
2.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <mc@jvavav.com>
Date: Fri, 28 Mar 2025 21:19:19 +0800
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..ad66046d31c24ba2a7d2b115f6c70adb95b9735b 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
}
private CompoundTag getData() {
- return this.storage.load(this.profile.getName(), this.profile.getId().toString()).orElse(null);
+ return this.storage.load(this.profile.getName(), this.profile.getId().toString(), this.profile.getId()).orElse(null); // Leaf - Async player IO
}
private CompoundTag getBukkitData() {
@@ -813,16 +813,7 @@ 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();
- }
+ server.console.playerDataStorage.save(this.getName(), this.getUniqueId(), this.getUniqueId().toString(), compoundTag); // Leaf - Async player IO
}
// Purpur end - OfflinePlayer API
}