summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Events
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/Events')
-rw-r--r--src/SMAPI/Framework/Events/ManagedEvent.cs38
1 files changed, 10 insertions, 28 deletions
diff --git a/src/SMAPI/Framework/Events/ManagedEvent.cs b/src/SMAPI/Framework/Events/ManagedEvent.cs
index b0f0ae71..b37fb376 100644
--- a/src/SMAPI/Framework/Events/ManagedEvent.cs
+++ b/src/SMAPI/Framework/Events/ManagedEvent.cs
@@ -90,8 +90,13 @@ namespace StardewModdingAPI.Framework.Events
/// <summary>Raise the event and notify all handlers.</summary>
/// <param name="args">The event arguments to pass.</param>
- public void Raise(TEventArgs args)
+ /// <param name="match">A lambda which returns true if the event should be raised for the given mod.</param>
+ public void Raise(TEventArgs args, Func<IModMetadata, bool> match = null)
{
+ // skip if no handlers
+ if (this.EventHandlers.Count == 0)
+ return;
+
// sort event handlers by priority
// (This is done here to avoid repeatedly sorting when handlers are added/removed.)
if (this.NeedsSort)
@@ -100,13 +105,14 @@ namespace StardewModdingAPI.Framework.Events
this.EventHandlers.Sort();
}
- // raise
- if (this.EventHandlers.Count == 0)
- return;
+ // raise event
this.PerformanceMonitor.Track(this.EventName, () =>
{
foreach (ManagedEventHandler<TEventArgs> handler in this.EventHandlers)
{
+ if (match != null && !match(handler.SourceMod))
+ continue;
+
try
{
this.PerformanceMonitor.Track(this.EventName, this.GetModNameForPerformanceCounters(handler), () => handler.Handler.Invoke(null, args));
@@ -119,30 +125,6 @@ namespace StardewModdingAPI.Framework.Events
});
}
- /// <summary>Raise the event and notify all handlers.</summary>
- /// <param name="args">The event arguments to pass.</param>
- /// <param name="match">A lambda which returns true if the event should be raised for the given mod.</param>
- public void RaiseForMods(TEventArgs args, Func<IModMetadata, bool> match)
- {
- if (this.EventHandlers.Count == 0)
- return;
-
- foreach (ManagedEventHandler<TEventArgs> handler in this.EventHandlers)
- {
- if (match(handler.SourceMod))
- {
- try
- {
- handler.Handler.Invoke(null, args);
- }
- catch (Exception ex)
- {
- this.LogError(handler, ex);
- }
- }
- }
- }
-
/*********
** Private methods