diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-12-12 00:16:34 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-12-12 00:16:34 -0500 |
commit | d04cacbdd0729140e4d8e93323ba66ee90ff9d2a (patch) | |
tree | 850abb470a8e8f6c8e6cf4a7db7a6c6ffaeada7b /src/SMAPI/Framework/ModHelpers | |
parent | 7d644aeabee63c0d51d4e89360d2fdab0e51b8be (diff) | |
download | SMAPI-d04cacbdd0729140e4d8e93323ba66ee90ff9d2a.tar.gz SMAPI-d04cacbdd0729140e4d8e93323ba66ee90ff9d2a.tar.bz2 SMAPI-d04cacbdd0729140e4d8e93323ba66ee90ff9d2a.zip |
log mod-provided API access (#409)
Diffstat (limited to 'src/SMAPI/Framework/ModHelpers')
-rw-r--r-- | src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs index 949d986a..827c77d5 100644 --- a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs @@ -12,6 +12,12 @@ namespace StardewModdingAPI.Framework.ModHelpers /// <summary>The underlying mod registry.</summary> private readonly ModRegistry Registry; + /// <summary>Encapsulates monitoring and logging for the mod.</summary> + private readonly IMonitor Monitor; + + /// <summary>The mod IDs for APIs accessed by this instanced.</summary> + private readonly HashSet<string> AccessedModApis = new HashSet<string>(); + /********* ** Public methods @@ -19,10 +25,12 @@ namespace StardewModdingAPI.Framework.ModHelpers /// <summary>Construct an instance.</summary> /// <param name="modID">The unique ID of the relevant mod.</param> /// <param name="registry">The underlying mod registry.</param> - public ModRegistryHelper(string modID, ModRegistry registry) + /// <param name="monitor">Encapsulates monitoring and logging for the mod.</param> + public ModRegistryHelper(string modID, ModRegistry registry, IMonitor monitor) : base(modID) { this.Registry = registry; + this.Monitor = monitor; } /// <summary>Get metadata for all loaded mods.</summary> @@ -49,7 +57,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /// <summary>Get the API provided by a mod, or <c>null</c> if it has none. This signature requires using the <see cref="IModHelper.Reflection"/> API to access the API's properties and methods.</summary> public object GetApi(string uniqueID) { - return this.Registry.Get(uniqueID)?.Api; + IModMetadata mod = this.Registry.Get(uniqueID); + if (mod?.Api != null && this.AccessedModApis.Add(mod.Manifest.UniqueID)) + this.Monitor.Log($"Accessed mod-provided API for {mod.DisplayName}.", LogLevel.Trace); + return mod?.Api; } } } |