diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-11-04 23:18:55 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-11-04 23:18:55 -0500 |
commit | e8276166c3e8d1a0b3a976ef29a00f8e1569cc72 (patch) | |
tree | a78c44e929ff1de70d20b012385c418aea7e78a6 /src/SMAPI/Framework/Events/ManagedEvent.cs | |
parent | 688ee69ee64e03aee7a693e6c15092daf229ac5e (diff) | |
parent | b4a5b3829f0f738e5b7e05048068eaec9d2d01d1 (diff) | |
download | SMAPI-e8276166c3e8d1a0b3a976ef29a00f8e1569cc72.tar.gz SMAPI-e8276166c3e8d1a0b3a976ef29a00f8e1569cc72.tar.bz2 SMAPI-e8276166c3e8d1a0b3a976ef29a00f8e1569cc72.zip |
Merge branch 'add-multiplayer-sync' into develop
Diffstat (limited to 'src/SMAPI/Framework/Events/ManagedEvent.cs')
-rw-r--r-- | src/SMAPI/Framework/Events/ManagedEvent.cs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/Events/ManagedEvent.cs b/src/SMAPI/Framework/Events/ManagedEvent.cs index c1ebf6c7..65f6e38e 100644 --- a/src/SMAPI/Framework/Events/ManagedEvent.cs +++ b/src/SMAPI/Framework/Events/ManagedEvent.cs @@ -67,6 +67,30 @@ 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.Event == null) + return; + + foreach (EventHandler<TEventArgs> handler in this.CachedInvocationList) + { + if (match(this.GetSourceMod(handler))) + { + try + { + handler.Invoke(null, args); + } + catch (Exception ex) + { + this.LogError(handler, ex); + } + } + } + } } /// <summary>An event wrapper which intercepts and logs errors in handler code.</summary> |