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 {
/**
* Saves all worlds and players data.
* Saves all worlds and players data on the main thread.
*
* @return boolean
*/
public static boolean Run(){
public static boolean Run() {
STPlugin plugin = STPlugin.getInstance();
String p = plugin.getConfig().getString("Saving.broadcastMsgProgress").replace("{PREFIX}",plugin.getPrefix());
String d = plugin.getConfig().getString("Saving.broadcastMsgDone").replace("{PREFIX}",plugin.getPrefix());
Bukkit.broadcast(p,"st.st");
for(World w : Bukkit.getServer().getWorlds()){
w.save();
}
Bukkit.savePlayers();
Bukkit.broadcast(d,"st.st");
String prefix = plugin.getPrefix();
String progressMsg = plugin.getConfig().getString("Saving.broadcastMsgProgress").replace("{PREFIX}", prefix);
String doneMsg = plugin.getConfig().getString("Saving.broadcastMsgDone").replace("{PREFIX}", prefix);
// 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
}
// Save player data
Bukkit.savePlayers(); // Also runs on main thread
// Notify players of save completion
Bukkit.broadcast(doneMsg, "st.st");
});
return true;
}
}