    001package net.minecraft.command;
    002
    003import net.minecraft.server.MinecraftServer;
    004import net.minecraft.util.IProgressUpdate;
    005import net.minecraft.world.MinecraftException;
    006import net.minecraft.world.WorldServer;
    007
    008public class CommandServerSaveAll extends CommandBase
    009{
    010    public String getCommandName()
    011    {
    012        return "save-all";
    013    }
    014
    015    /**
    016     * Return the required permission level for this command.
    017     */
    018    public int getRequiredPermissionLevel()
    019    {
    020        return 4;
    021    }
    022
    023    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    024    {
    025        MinecraftServer minecraftserver = MinecraftServer.getServer();
    026        par1ICommandSender.sendChatToPlayer(par1ICommandSender.translateString("commands.save.start", new Object[0]));
    027
    028        if (minecraftserver.getConfigurationManager() != null)
    029        {
    030            minecraftserver.getConfigurationManager().saveAllPlayerData();
    031        }
    032
    033        try
    034        {
    035            for (int i = 0; i < minecraftserver.worldServers.length; ++i)
    036            {
    037                if (minecraftserver.worldServers[i] != null)
    038                {
    039                    WorldServer worldserver = minecraftserver.worldServers[i];
    040                    boolean flag = worldserver.canNotSave;
    041                    worldserver.canNotSave = false;
    042                    worldserver.saveAllChunks(true, (IProgressUpdate)null);
    043                    worldserver.canNotSave = flag;
    044                }
    045            }
    046        }
    047        catch (MinecraftException minecraftexception)
    048        {
    049            notifyAdmins(par1ICommandSender, "commands.save.failed", new Object[] {minecraftexception.getMessage()});
    050            return;
    051        }
    052
    053        notifyAdmins(par1ICommandSender, "commands.save.success", new Object[0]);
    054    }
    055}