userbankaccount balancechanged dont crash server

This commit is contained in:
hydrant
2021-04-11 14:20:29 +02:00
parent 4ec4875701
commit e82d467d4e
2 changed files with 26 additions and 14 deletions

View File

@@ -187,21 +187,23 @@ namespace ReallifeGamemode.Server.Finance
public static void Timer_Elapsed()
{
using var dbContext = new DatabaseContext();
foreach (var player in NAPI.Pools.GetAllPlayers())
foreach (var player in NAPI.Pools.GetAllPlayers().Where(p => p.IsLoggedIn()))
{
User user = player.GetUser(dbContext);
if (player.IsLoggedIn())
if(user == null)
{
user.PlayedMinutes += 1;
if (user.PaydayTimer <= 0)
{
Economy.SetPaycheck(player);
user.PaydayTimer = 60;
}
else if (user.PaydayTimer > 0)
{
user.PaydayTimer -= 1;
}
continue;
}
user.PlayedMinutes += 1;
if (user.PaydayTimer <= 0)
{
Economy.SetPaycheck(player);
user.PaydayTimer = 60;
}
else if (user.PaydayTimer > 0)
{
user.PaydayTimer -= 1;
}
}
dbContext.SaveChanges();