Minor optimizations in save command
This commit is contained in:
		| @@ -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"); | ||||||
|         Bukkit.savePlayers(); |  | ||||||
|         Bukkit.broadcast(d,"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; |         return true; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user