Minor optimizations in save command

This commit is contained in:
LabodiDavid 2024-12-12 22:28:56 +01:00
parent 619548297d
commit 27c9de4776

View File

@ -6,20 +6,33 @@ import org.bukkit.World;
public class SaveCommand { public class SaveCommand {
/** /**
* Saves all worlds and players data. * Saves all worlds and players data on the main thread.
* *
* @return boolean * @return boolean
*/ */
public static boolean Run() { public static boolean Run() {
STPlugin plugin = STPlugin.getInstance(); STPlugin plugin = STPlugin.getInstance();
String p = plugin.getConfig().getString("Saving.broadcastMsgProgress").replace("{PREFIX}",plugin.getPrefix()); String prefix = plugin.getPrefix();
String d = plugin.getConfig().getString("Saving.broadcastMsgDone").replace("{PREFIX}",plugin.getPrefix()); String progressMsg = plugin.getConfig().getString("Saving.broadcastMsgProgress").replace("{PREFIX}", prefix);
Bukkit.broadcast(p,"st.st"); String doneMsg = plugin.getConfig().getString("Saving.broadcastMsgDone").replace("{PREFIX}", prefix);
for(World w : Bukkit.getServer().getWorlds()){
w.save(); // Notify players of save progress
Bukkit.broadcast(progressMsg, "st.st");
// Schedule task to run on the main thread
Bukkit.getScheduler().runTask(plugin, () -> {
// Save all worlds
for (World world : Bukkit.getServer().getWorlds()) {
world.save(); // Runs on main thread
} }
Bukkit.savePlayers();
Bukkit.broadcast(d,"st.st"); // Save player data
Bukkit.savePlayers(); // Also runs on main thread
// Notify players of save completion
Bukkit.broadcast(doneMsg, "st.st");
});
return true; return true;
} }
} }