summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Events/ManagedEvent.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-06-15 19:08:02 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-06-15 19:08:02 -0400
commit02e7318d2b99d311a328746b23a359364575f0c5 (patch)
treead1de7e9991235b3262e1ab68c3b6e4159742b28 /src/SMAPI/Framework/Events/ManagedEvent.cs
parentda95a906bf8e812ddcd99a90a4d49942f02f5623 (diff)
downloadSMAPI-02e7318d2b99d311a328746b23a359364575f0c5.tar.gz
SMAPI-02e7318d2b99d311a328746b23a359364575f0c5.tar.bz2
SMAPI-02e7318d2b99d311a328746b23a359364575f0c5.zip
merge inconsistent event raise methods
Diffstat (limited to 'src/SMAPI/Framework/Events/ManagedEvent.cs')
-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