diff --git a/MiraAPI/Events/MiraEventManager.cs b/MiraAPI/Events/MiraEventManager.cs index b5bbfad9..b8c78141 100644 --- a/MiraAPI/Events/MiraEventManager.cs +++ b/MiraAPI/Events/MiraEventManager.cs @@ -122,7 +122,7 @@ public static class MiraEventManager /// The priority of the event handler. Lower values are called first. /// Whether the event handler should also be triggered by subclasses of the type of the handler. /// A to use when unregistering the event. - public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, int priority = 0, bool invokeOnSubtype = true) + public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, int priority, bool invokeOnSubtype) { if (!type.IsAssignableTo(typeof(MiraEvent))) { @@ -133,6 +133,24 @@ public static class MiraEventManager return RegisterEventHandler(type, @delegate, priority, invokeOnSubtype); } + /// + public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, int priority) + { + return RegisterEventHandler(type, methodInfo, priority, true); + } + + /// + public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo, bool invokeOnSubtype) + { + return RegisterEventHandler(type, methodInfo, 0, invokeOnSubtype); + } + + /// + public static MiraEventHandle RegisterEventHandler(Type type, MethodInfo methodInfo) + { + return RegisterEventHandler(type, methodInfo, 0, true); + } + /// /// Register a handler. /// @@ -140,11 +158,29 @@ public static class MiraEventManager /// The priority of the event handler. Lower values are called first. /// Whether the event handler should also be triggered by subclasses of the type of the handler. /// A to use when unregistering the event. - public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo, int priority = 0, bool invokeOnSubtype = true) + public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo, int priority, bool invokeOnSubtype) { return RegisterEventHandler(methodInfo.GetParameters()[0].ParameterType, methodInfo, priority, invokeOnSubtype); } + /// + public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo, int priority) + { + return RegisterEventHandler(methodInfo, priority, true); + } + + /// + public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo, bool invokeOnSubtype) + { + return RegisterEventHandler(methodInfo, 0, invokeOnSubtype); + } + + /// + public static MiraEventHandle RegisterEventHandler(MethodInfo methodInfo) + { + return RegisterEventHandler(methodInfo, 0, true); + } + /// /// Register a handler. /// @@ -153,12 +189,33 @@ public static class MiraEventManager /// Whether the event handler should also be triggered by subclasses of the type of the handler. /// Type of event. /// A to use when unregistering the event. - public static MiraEventHandle RegisterEventHandler(Action handler, int priority = 0, bool invokeOnSubtype = true) + public static MiraEventHandle RegisterEventHandler(Action handler, int priority, bool invokeOnSubtype) where T : MiraEvent { return RegisterEventHandler(typeof(T), handler, priority, invokeOnSubtype); } + /// + public static MiraEventHandle RegisterEventHandler(Action handler, int priority) + where T : MiraEvent + { + return RegisterEventHandler(handler, priority, true); + } + + /// + public static MiraEventHandle RegisterEventHandler(Action handler, bool invokeOnSubtype) + where T : MiraEvent + { + return RegisterEventHandler(handler, 0, invokeOnSubtype); + } + + /// + public static MiraEventHandle RegisterEventHandler(Action handler) + where T : MiraEvent + { + return RegisterEventHandler(handler, 0, true); + } + /// /// Register a handler. /// diff --git a/MiraAPI/Events/RegisterEventAttribute.cs b/MiraAPI/Events/RegisterEventAttribute.cs index c3a6b736..00684595 100644 --- a/MiraAPI/Events/RegisterEventAttribute.cs +++ b/MiraAPI/Events/RegisterEventAttribute.cs @@ -8,7 +8,7 @@ namespace MiraAPI.Events; /// The priority of the event. Lower values are called first. /// Whether the event handler should also be triggered by subclasses of the type of the handler. [AttributeUsage(AttributeTargets.Method)] -public class RegisterEventAttribute(int priority = 0, bool invokeOnSubtype = true) : Attribute +public class RegisterEventAttribute(int priority, bool invokeOnSubtype) : Attribute { /// /// Gets the priority of the event. Lower values are called first. @@ -20,4 +20,22 @@ public class RegisterEventAttribute(int priority = 0, bool invokeOnSubtype = tru /// triggered by subclasses of the type of the handler. /// public bool InvokeOnSubtype { get; } = invokeOnSubtype; + + /// + public RegisterEventAttribute(int priority) + : this(priority, true) + { + } + + /// + public RegisterEventAttribute(bool invokeOnSubtype) + : this(0, invokeOnSubtype) + { + } + + /// + public RegisterEventAttribute() + : this(0, true) + { + } }