diff --git a/MiraAPI/Events/Vanilla/Meeting/Voting/CheckForEndVotingEvent.cs b/MiraAPI/Events/Vanilla/Meeting/Voting/CheckForEndVotingEvent.cs new file mode 100644 index 0000000..b0bdae5 --- /dev/null +++ b/MiraAPI/Events/Vanilla/Meeting/Voting/CheckForEndVotingEvent.cs @@ -0,0 +1,26 @@ +namespace MiraAPI.Events.Vanilla.Meeting.Voting; + +/// +/// Checks if voting is complete. If canceled, the default end voting logic will be skipped. +/// +public class CheckForEndVotingEvent : MiraCancelableEvent +{ + /// + /// Gets a value indicating whether default voting logic determines that voting is complete. + /// + public bool IsVotingComplete { get; } + + /// + /// Gets or sets a value indicating whether the voting should be forced to end, regardless of the default logic. + /// + public bool ForceEndVoting { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// >True if voting is complete, false otherwise. + public CheckForEndVotingEvent(bool isVotingComplete) + { + IsVotingComplete = isVotingComplete; + } +} diff --git a/MiraAPI/Patches/Voting/MeetingHudPatches.cs b/MiraAPI/Patches/Voting/MeetingHudPatches.cs index c7babda..25bb2f0 100644 --- a/MiraAPI/Patches/Voting/MeetingHudPatches.cs +++ b/MiraAPI/Patches/Voting/MeetingHudPatches.cs @@ -173,7 +173,13 @@ internal static class MeetingHudPatches [HarmonyPatch(nameof(MeetingHud.CheckForEndVoting))] public static bool EndCheck(MeetingHud __instance) { - if (Helpers.GetAlivePlayers().Exists(plr => plr.GetVoteData().VotesRemaining > 0)) + var shouldEnd = Helpers.GetAlivePlayers().Exists(plr => plr.GetVoteData().VotesRemaining > 0); + + var checkEndEvent = new CheckForEndVotingEvent(shouldEnd); + MiraEventManager.InvokeEvent(checkEndEvent); + shouldEnd = checkEndEvent.ForceEndVoting || checkEndEvent is { IsCancelled: false, IsVotingComplete: true }; + + if (!shouldEnd) { return false; }