diff --git a/EndConditions/Commands/TestConditions.cs b/EndConditions/Commands/TestConditions.cs new file mode 100644 index 0000000..6398a57 --- /dev/null +++ b/EndConditions/Commands/TestConditions.cs @@ -0,0 +1,29 @@ +namespace EndConditions.Commands +{ + using CommandSystem; + using Exiled.API.Enums; + using Exiled.Events.EventArgs; + using Exiled.Permissions.Extensions; + using System; + + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class TestConditions : ICommand + { + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + if (!sender.CheckPermission("ec.test")) + { + response = "Insufficient permission. Required: ec.test"; + return false; + } + + EndConditions.EventHandlers.OnCheckRoundEnd(new EndingRoundEventArgs(LeadingTeam.Draw, default, false)); + response = "Fired event."; + return true; + } + + public string Command { get; } = "testconditions"; + public string[] Aliases { get; } = Array.Empty(); + public string Description { get; } = "Fires the EndingRound method once. Used for debugging."; + } +} \ No newline at end of file diff --git a/EndConditions/EndConditions.cs b/EndConditions/EndConditions.cs index 836d116..7e584e2 100755 --- a/EndConditions/EndConditions.cs +++ b/EndConditions/EndConditions.cs @@ -16,13 +16,13 @@ public class EndConditions : Plugin { private static readonly string ConfigsDirectory = Path.Combine(Paths.Configs, "EndConditions"); private static readonly string FileDirectory = Path.Combine(ConfigsDirectory, "config.yml"); - private EventHandlers _eventHandlers; + internal static EventHandlers EventHandlers; public override void OnEnabled() { - _eventHandlers = new EventHandlers(Config); - ServerHandlers.RoundStarted += _eventHandlers.OnRoundStart; - ServerHandlers.EndingRound += _eventHandlers.OnCheckRoundEnd; + EventHandlers = new EventHandlers(Config); + ServerHandlers.RoundStarted += EventHandlers.OnRoundStart; + ServerHandlers.EndingRound += EventHandlers.OnCheckRoundEnd; LoadConditions(); base.OnEnabled(); } @@ -30,9 +30,9 @@ public override void OnEnabled() public override void OnDisabled() { EventHandlers.Conditions.Clear(); - ServerHandlers.RoundStarted -= _eventHandlers.OnRoundStart; - ServerHandlers.EndingRound -= _eventHandlers.OnCheckRoundEnd; - _eventHandlers = null; + ServerHandlers.RoundStarted -= EventHandlers.OnRoundStart; + ServerHandlers.EndingRound -= EventHandlers.OnCheckRoundEnd; + EventHandlers = null; } public override string Author => "Build"; diff --git a/EndConditions/EventHandlers.cs b/EndConditions/EventHandlers.cs index 809fb12..c4c3354 100755 --- a/EndConditions/EventHandlers.cs +++ b/EndConditions/EventHandlers.cs @@ -41,6 +41,7 @@ public void OnCheckRoundEnd(EndingRoundEventArgs ev) if (Warhead.IsDetonated && _config.EndOnDetonation) { + Log.Debug("Ending the round via warhead detonation.", _config.AllowDebug); EndGame(ev, _config.DetonationWinner); return; } @@ -50,8 +51,10 @@ public void OnCheckRoundEnd(EndingRoundEventArgs ev) _escAdditions["-science"] = RoundSummary.escaped_scientists == 0; _escAdditions["+science"] = RoundSummary.escaped_scientists != 0; + IEnumerable roles = GetRoles(); + // Pull all the lists from the core dictionary and check em - foreach (var condition in Conditions.Where(condition => !GetRoles().Except(condition.RoleConditions).Any())) + foreach (var condition in Conditions.Where(condition => !roles.Except(condition.RoleConditions).Any())) { try { @@ -82,7 +85,7 @@ private IEnumerable GetRoles() List list = new List(); foreach (Player ply in Player.List) { - if (ply.Role == RoleType.Spectator || API.BlacklistedPlayers.Contains(ply)) + if (string.IsNullOrEmpty(ply.UserId) || ply.Role == RoleType.Spectator || API.BlacklistedPlayers.Contains(ply)) continue; if (API.ModifiedRoles.ContainsKey(ply))