Skip to content

Commit

Permalink
Фикс
Browse files Browse the repository at this point in the history
  • Loading branch information
VigersRay committed Nov 13, 2024
1 parent 90f6910 commit 1570312
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions Content.Server/Voting/Managers/VoteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,23 @@ private void EndVote(VoteReg v)
}

// Find winner or stalemate.
var winners = v.Entries
.GroupBy(e => e.Votes)
.OrderByDescending(g => g.Key)
.First()
.Select(e => e.Data)
.ToImmutableArray();
// Sunrise-Start: На случай пустых голосований
ImmutableArray<object> winners;
if (v.Entries.Any())
{
winners = v.Entries
.GroupBy(e => e.Votes)
.OrderByDescending(g => g.Key)
.First()
.Select(e => e.Data)
.ToImmutableArray();
}
else
{
winners = ImmutableArray<object>.Empty;
}
// Sunrise-End

// Store all votes in order for webhooks
var voteTally = new List<int>();
foreach(var entry in v.Entries)
Expand All @@ -408,8 +419,18 @@ private void EndVote(VoteReg v)

v.Finished = true;
v.Dirty = true;
var args = new VoteFinishedEventArgs(winners.Length == 1 ? winners[0] : null, winners, voteTally);
v.OnFinished?.Invoke(_voteHandles[v.Id], args);
// Sunrise-Start: На случай пустых голосований
if (_voteHandles.ContainsKey(v.Id))
{
var args = new VoteFinishedEventArgs(winners.Length == 1 ? winners[0] : null, winners, voteTally);
v.OnFinished?.Invoke(_voteHandles[v.Id], args);
}
else
{
Logger.Error($"Vote handle with Id {v.Id} does not exist in _voteHandles.");
}
// Sunrise-End

DirtyCanCallVoteAll();
}

Expand Down

0 comments on commit 1570312

Please sign in to comment.