diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-11 19:15:22 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-11 19:15:22 -0400 |
commit | cae1063ad99a29aed3a0c162bad1d2842376c608 (patch) | |
tree | 5d1d3396cbbc42175fdbbd447f81223bd550a4ad /src/SMAPI/Framework | |
parent | 45f674303454fb27327a0404ed403ac15ed04580 (diff) | |
download | SMAPI-cae1063ad99a29aed3a0c162bad1d2842376c608.tar.gz SMAPI-cae1063ad99a29aed3a0c162bad1d2842376c608.tar.bz2 SMAPI-cae1063ad99a29aed3a0c162bad1d2842376c608.zip |
move filtering only used in one place out of managed event
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r-- | src/SMAPI/Framework/Events/ManagedEvent.cs | 6 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 13 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/SMAPI/Framework/Events/ManagedEvent.cs b/src/SMAPI/Framework/Events/ManagedEvent.cs index abeea098..a34106ce 100644 --- a/src/SMAPI/Framework/Events/ManagedEvent.cs +++ b/src/SMAPI/Framework/Events/ManagedEvent.cs @@ -118,8 +118,7 @@ namespace StardewModdingAPI.Framework.Events /// <summary>Raise the event and notify all handlers.</summary> /// <param name="invoke">Invoke an event handler. This receives the mod which registered the handler, and should invoke the callback with the event arguments to pass it.</param> - /// <param name="match">A lambda which returns true if the event should be raised for the given mod.</param> - public void Raise(Action<IModMetadata, Action<TEventArgs>> invoke, Func<IModMetadata, bool>? match = null) + public void Raise(Action<IModMetadata, Action<TEventArgs>> invoke) { // skip if no handlers if (this.Handlers.Count == 0) @@ -128,9 +127,6 @@ namespace StardewModdingAPI.Framework.Events // raise event foreach (ManagedEventHandler<TEventArgs> handler in this.GetHandlers()) { - if (match != null && !match(handler.SourceMod)) - continue; - try { invoke(handler.SourceMod, args => handler.Handler(null, args)); diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index c3f0c05f..1fea6d69 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1231,8 +1231,17 @@ namespace StardewModdingAPI.Framework modIDs.Remove(message.FromModID); // don't send a broadcast back to the sender // raise events - var args = new ModMessageReceivedEventArgs(message, this.Toolkit.JsonHelper); - this.EventManager.ModMessageReceived.Raise((_, invoke) => invoke(args), mod => modIDs.Contains(mod.Manifest.UniqueID)); + ModMessageReceivedEventArgs? args = null; + this.EventManager.ModMessageReceived.Raise( + invoke: (mod, invoke) => + { + if (modIDs.Contains(mod.Manifest.UniqueID)) + { + args ??= new(message, this.Toolkit.JsonHelper); + invoke(args); + } + } + ); } /// <summary>Constructor a content manager to read game content files.</summary> |