fix fehler bei server close
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using GTANetworkAPI;
|
using GTANetworkAPI;
|
||||||
|
using ReallifeGamemode.Database.Entities;
|
||||||
using ReallifeGamemode.Database.Models;
|
using ReallifeGamemode.Database.Models;
|
||||||
using ReallifeGamemode.Server.Extensions;
|
using ReallifeGamemode.Server.Extensions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -16,31 +17,27 @@ namespace ReallifeGamemode.Server.Events
|
|||||||
[ServerEvent(Event.ResourceStop)]
|
[ServerEvent(Event.ResourceStop)]
|
||||||
public void OnResourceStop()
|
public void OnResourceStop()
|
||||||
{
|
{
|
||||||
foreach (var player in NAPI.Pools.GetAllPlayers())
|
|
||||||
|
using (var dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
using (var dbContext = new DatabaseContext())
|
foreach (var player in NAPI.Pools.GetAllPlayers())
|
||||||
{
|
{
|
||||||
player.GetUser(dbContext).PositionX = player.Position.X;
|
player.TriggerEvent("CLIENT:StopSound");
|
||||||
player.GetUser(dbContext).PositionY = player.Position.Y;
|
|
||||||
player.GetUser(dbContext).PositionZ = player.Position.Z;
|
User user = player.GetUser(dbContext);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.PositionX = player.Position.X;
|
||||||
|
user.PositionY = player.Position.Y;
|
||||||
|
user.PositionZ = player.Position.Z;
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var users = NAPI.Pools.GetAllPlayers();
|
|
||||||
|
|
||||||
foreach (Player user in users)
|
|
||||||
{
|
|
||||||
user.TriggerEvent("CLIENT:StopSound");
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user