From 33f4c1550ccbd41bf216d65a6fa168fd5140db8c Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Tue, 13 Dec 2022 13:56:47 +0100 Subject: [PATCH] Added WorldSaveUtil --- .../lib/paper/reflect/util/WorldSaveUtil.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pandalib-paper-reflect/src/main/java/fr/pandacube/lib/paper/reflect/util/WorldSaveUtil.java diff --git a/pandalib-paper-reflect/src/main/java/fr/pandacube/lib/paper/reflect/util/WorldSaveUtil.java b/pandalib-paper-reflect/src/main/java/fr/pandacube/lib/paper/reflect/util/WorldSaveUtil.java new file mode 100644 index 0000000..fd80bff --- /dev/null +++ b/pandalib-paper-reflect/src/main/java/fr/pandacube/lib/paper/reflect/util/WorldSaveUtil.java @@ -0,0 +1,35 @@ +package fr.pandacube.lib.paper.reflect.util; + +import org.bukkit.Bukkit; +import org.bukkit.World; + +import fr.pandacube.lib.chat.Chat; +import fr.pandacube.lib.chat.ChatConfig.PandaTheme; +import fr.pandacube.lib.paper.modules.PerformanceAnalysisManager; +import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftWorld; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ChunkMap; +import fr.pandacube.lib.reflect.wrapper.ReflectWrapper; + +public class WorldSaveUtil { + + private static ChunkMap getChunkMap(World w) { + return ReflectWrapper.wrapTyped(w, CraftWorld.class).getHandle().getChunkSource().chunkMap; + } + + public static void nmsSaveFlush(World w) { + PerformanceAnalysisManager.getInstance().setAlteredTPSTitle( + Chat.text("Sauvegarde map ").color(PandaTheme.CHAT_BROWN_2_SAT).thenData(w.getName()).thenText(" ...") + ); + + try { + ReflectWrapper.wrapTyped(w, CraftWorld.class).getHandle().save(null, true, false); + } finally { + PerformanceAnalysisManager.getInstance().setAlteredTPSTitle(null); + } + } + + public static void nmsSaveAllFlush() { + Bukkit.getWorlds().forEach(WorldSaveUtil::nmsSaveFlush); + } + +}