From 46689a360c5059c8e906c4f8d1e358f966a35b55 Mon Sep 17 00:00:00 2001 From: laforetbrut Date: Thu, 26 Mar 2026 17:24:18 +0100 Subject: [PATCH] Fix advancements disappearing on server transfer Minecraft only flushes PlayerAdvancements to disk during auto-save (~every 5 min). If a player earns an advancement and switches servers before the next auto-save, store() reads the stale file and the advancement is lost in the DB. Fix: call sp.getAdvancements().save() to force flush to disk before reading the advancement file in store(). Vyrriox --- .../java/vip/fubuki/playersync/sync/VanillaSync.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/vip/fubuki/playersync/sync/VanillaSync.java b/src/main/java/vip/fubuki/playersync/sync/VanillaSync.java index 2bf72f7..737e9d7 100644 --- a/src/main/java/vip/fubuki/playersync/sync/VanillaSync.java +++ b/src/main/java/vip/fubuki/playersync/sync/VanillaSync.java @@ -835,6 +835,18 @@ public class VanillaSync { File advancements = null; byte[] advancementBytes = new byte[0]; if (JdbcConfig.SYNC_ADVANCEMENTS.get()) { + // FIX: Force Minecraft to flush the player's advancements to disk BEFORE reading the file. + // Without this, recently earned advancements may not be in the file yet (Minecraft only + // flushes advancements during auto-save ~every 5 min). If the player switches servers + // before the next auto-save, the stale file is read and new advancements are lost. + if (player instanceof ServerPlayer sp) { + try { + sp.getAdvancements().save(); + } catch (Exception e) { + PlayerSync.LOGGER.warn("Failed to flush advancements to disk for player {}", player_uuid, e); + } + } + Path path = player.getServer().getServerDirectory().resolve(getSyncWorldForServer()); File gameDir = path.toFile(); final MinecraftServer server = ServerLifecycleHooks.getCurrentServer();