using GTANetworkAPI;
using GTANetworkMethods;
using ReallifeGamemode.Server.Entities;
using ReallifeGamemode.Server.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/**
* @overview Life of German Reallife - Event ResourceStop (ResourceStop.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/

namespace ReallifeGamemode.Server.Events
{
    public class ResourceStop : Script
    {
        [ServerEvent(Event.ResourceStop)]
        public void OnResourceStop()
        {
            var users = NAPI.Pools.GetAllPlayers();

            foreach (Client user in users)
            {
                using (var saveUsers = new DatabaseContext())
                {
                    var saveUser = saveUsers.Users.SingleOrDefault(u => u.Name == user.Name);

                    saveUser.PositionX = user.Position.X;
                    saveUser.PositionY = user.Position.Y;
                    saveUser.PositionZ = user.Position.Z;
                    saveUsers.SaveChanges();
                }
            }
        }
    }
}
