#nullable disable using System; using StardewModdingAPI.Events; namespace StardewModdingAPI.Framework.Events { /// An event handler wrapper which tracks metadata about an event handler. /// The event arguments type. internal class ManagedEventHandler : IComparable { /********* ** Accessors *********/ /// The event handler method. public EventHandler Handler { get; } /// The order in which the event handler was registered, relative to other handlers for this event. public int RegistrationOrder { get; } /// The event handler priority, relative to other handlers for this event. public EventPriority Priority { get; } /// The mod which registered the handler. public IModMetadata SourceMod { get; set; } /********* ** Accessors *********/ /// Construct an instance. /// The event handler method. /// The order in which the event handler was registered, relative to other handlers for this event. /// The event handler priority, relative to other handlers for this event. /// The mod which registered the handler. public ManagedEventHandler(EventHandler handler, int registrationOrder, EventPriority priority, IModMetadata sourceMod) { this.Handler = handler; this.RegistrationOrder = registrationOrder; this.Priority = priority; this.SourceMod = sourceMod; } /// public int CompareTo(object obj) { if (obj is not ManagedEventHandler other) throw new ArgumentException("Can't compare to an unrelated object type."); int priorityCompare = -this.Priority.CompareTo(other.Priority); // higher value = sort first return priorityCompare != 0 ? priorityCompare : this.RegistrationOrder.CompareTo(other.RegistrationOrder); } } }