From 9557892dafba86038b50fe3b30adc780fe346595 Mon Sep 17 00:00:00 2001
From: Az <56699741+AlchlcDvl@users.noreply.github.com>
Date: Sat, 7 Nov 2026 16:42:18 -0500
Subject: [PATCH] use newer event stuff + fix attribute
---
MiraAPI.Example/ExampleEventHandlers.cs | 1 +
MiraAPI.Example/ExamplePlugin.cs | 3 +++
MiraAPI/Events/RegisterEventsAttribute.cs | 2 +-
MiraAPI/MiraApiPlugin.cs | 6 +++---
MiraAPI/VanillaEvents/JudgeEvents.cs | 10 +++-------
MiraAPI/VanillaEvents/UiResetEvents.cs | 21 +++++++++------------
6 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/MiraAPI.Example/ExampleEventHandlers.cs b/MiraAPI.Example/ExampleEventHandlers.cs
index c14710a9..65265ad1 100644
--- a/MiraAPI.Example/ExampleEventHandlers.cs
+++ b/MiraAPI.Example/ExampleEventHandlers.cs
@@ -14,6 +14,7 @@ using Reactor.Utilities;
namespace MiraAPI.Example;
+[RegisterEventContainer]
public static class ExampleEventHandlers
{
public static void Initialize()
diff --git a/MiraAPI.Example/ExamplePlugin.cs b/MiraAPI.Example/ExamplePlugin.cs
index eadc271d..57812ded 100644
--- a/MiraAPI.Example/ExamplePlugin.cs
+++ b/MiraAPI.Example/ExamplePlugin.cs
@@ -26,6 +26,9 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin
public string OptionsTitleText { get; } = "Mira API\nExample Mod";
public string CustomOptionMenuNameTwo { get; } = "Example Options";
+ ///
+ public bool ForceRegisterEvents => false;
+
public ConfigFile GetConfigFile()
{
return Config;
diff --git a/MiraAPI/Events/RegisterEventsAttribute.cs b/MiraAPI/Events/RegisterEventsAttribute.cs
index 8b8a0184..9e6a1e63 100644
--- a/MiraAPI/Events/RegisterEventsAttribute.cs
+++ b/MiraAPI/Events/RegisterEventsAttribute.cs
@@ -5,5 +5,5 @@ namespace MiraAPI.Events;
///
/// Register a container of s.
///
-[AttributeUsage(AttributeTargets.Method)]
+[AttributeUsage(AttributeTargets.Class)]
public class RegisterEventContainerAttribute : Attribute;
diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs
index 7e744781..633145be 100644
--- a/MiraAPI/MiraApiPlugin.cs
+++ b/MiraAPI/MiraApiPlugin.cs
@@ -8,7 +8,6 @@ using MiraAPI.Patches;
using MiraAPI.Patches.Roles;
using MiraAPI.PluginLoading;
using MiraAPI.Translation;
-using MiraAPI.VanillaEvents;
using Reactor;
using Reactor.Localization;
using Reactor.Networking;
@@ -44,6 +43,9 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
///
public bool DebugMode => IsDevBuild;
+ ///
+ public bool ForceRegisterEvents => false;
+
///
/// Gets a value indicating whether the current device is running Starlight (on mobile).
///
@@ -96,8 +98,6 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
"Dictates the unit of distance used in numeric option displays representing a distance.");
Harmony.PatchAll();
RoleOptionsCollectionPatch.PatchRoleMethods(Harmony);
- UiResetEvents.Initialize();
- JudgeEvents.Initialize();
ReactorCredits.Register("Mira API", Version, IsDevBuild, ReactorCredits.AlwaysShow);
diff --git a/MiraAPI/VanillaEvents/JudgeEvents.cs b/MiraAPI/VanillaEvents/JudgeEvents.cs
index 6cfd5263..5a4b9fcd 100644
--- a/MiraAPI/VanillaEvents/JudgeEvents.cs
+++ b/MiraAPI/VanillaEvents/JudgeEvents.cs
@@ -4,15 +4,11 @@ using MiraAPI.Roles;
namespace MiraAPI.VanillaEvents;
+[RegisterEventContainer]
internal static class JudgeEvents
{
- public static void Initialize()
- {
- // This is required because MiraAPI isn't an IMiraPlugin (besides in the gamemodes branch)
- MiraEventManager.RegisterEventHandler(ProcessVotesEventHandler, -1000);
- }
-
- private static void ProcessVotesEventHandler(ProcessVotesEvent @event)
+ [RegisterEvent(-1000)]
+ public static void ProcessVotesEventHandler(ProcessVotesEvent @event)
{
if (!MeetingHud.Instance.TryGetWinningOverrule(
out var judgeOverrule,
diff --git a/MiraAPI/VanillaEvents/UiResetEvents.cs b/MiraAPI/VanillaEvents/UiResetEvents.cs
index 84d00225..37574f1e 100644
--- a/MiraAPI/VanillaEvents/UiResetEvents.cs
+++ b/MiraAPI/VanillaEvents/UiResetEvents.cs
@@ -5,17 +5,11 @@ using MiraAPI.LocalSettings;
namespace MiraAPI.VanillaEvents;
+[RegisterEventContainer]
internal static class UiResetEvents
{
- public static void Initialize()
- {
- MiraEventManager.RegisterEventHandler(ResetButtonParents);
- MiraEventManager.RegisterEventHandler(PlaceWikiButton, -900);
- MiraEventManager.RegisterEventHandler(PlaceSubmergedButton, -800);
- MiraEventManager.RegisterEventHandler(PlaceModifierUi, -700);
- }
-
- private static void ResetButtonParents(UiButtonResetEvent _)
+ [RegisterEvent]
+ public static void ResetButtonParents(UiButtonResetEvent _)
{
var wikiButton = MiraHudHelper.VanillaMatchInfoButton;
var subButton = MiraHudHelper.SubmergedFloorButton;
@@ -36,7 +30,8 @@ internal static class UiResetEvents
}
}
- private static void PlaceWikiButton(UiButtonPostResetEvent @event)
+ [RegisterEvent(-900)]
+ public static void PlaceWikiButton(UiButtonPostResetEvent @event)
{
var wikiButton = MiraHudHelper.VanillaMatchInfoButton;
if (!wikiButton)
@@ -50,7 +45,8 @@ internal static class UiResetEvents
wikiButton.transform.SetParent(opts.WikiOnBottomRow.Value ? secondRow.transform : firstRow.transform);
}
- private static void PlaceSubmergedButton(UiButtonPostResetEvent @event)
+ [RegisterEvent(-800)]
+ public static void PlaceSubmergedButton(UiButtonPostResetEvent @event)
{
var subButton = MiraHudHelper.SubmergedFloorButton;
if (!subButton)
@@ -62,7 +58,8 @@ internal static class UiResetEvents
subButton.transform.SetParent(secondRow.transform);
}
- private static void PlaceModifierUi(UiButtonPostResetEvent @event)
+ [RegisterEvent(-700)]
+ public static void PlaceModifierUi(UiButtonPostResetEvent @event)
{
var modDisplay = MiraHudHelper.ModifierDisplayOnRight ? MiraHudHelper.ModifierDisplayObject : null!;
if (!modDisplay)