fix mods receiving their own broadcasts

This commit is contained in:
Jesse Plamondon-Willard 2020-02-22 23:01:43 -05:00
parent f98f61e6d8
commit 02a96b54b5
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,9 @@
← [README](README.md) ← [README](README.md)
# Release notes # Release notes
## Upcoming release
* Fixed mods receiving their own message broadcasts.
## 3.3.1 ## 3.3.1
Released 22 February 2020 for Stardew Valley 1.4.1 or later. Released 22 February 2020 for Stardew Valley 1.4.1 or later.

View File

@ -226,8 +226,12 @@ namespace StardewModdingAPI.Framework
/// <param name="message">The message to deliver to applicable mods.</param> /// <param name="message">The message to deliver to applicable mods.</param>
private void OnModMessageReceived(ModMessageModel message) private void OnModMessageReceived(ModMessageModel message)
{ {
// raise events for applicable mods // get mod IDs to notify
HashSet<string> modIDs = new HashSet<string>(message.ToModIDs ?? this.ModRegistry.GetAll().Select(p => p.Manifest.UniqueID), StringComparer.InvariantCultureIgnoreCase); HashSet<string> modIDs = new HashSet<string>(message.ToModIDs ?? this.ModRegistry.GetAll().Select(p => p.Manifest.UniqueID), StringComparer.InvariantCultureIgnoreCase);
if (message.FromPlayerID == Game1.player?.UniqueMultiplayerID)
modIDs.Remove(message.FromModID); // don't send a broadcast back to the sender
// raise events
this.Events.ModMessageReceived.RaiseForMods(new ModMessageReceivedEventArgs(message), mod => mod != null && modIDs.Contains(mod.Manifest.UniqueID)); this.Events.ModMessageReceived.RaiseForMods(new ModMessageReceivedEventArgs(message), mod => mod != null && modIDs.Contains(mod.Manifest.UniqueID));
} }