block access to mod-provided APIs until all mods are initialised (#409)

This commit is contained in:
Jesse Plamondon-Willard 2017-12-12 01:33:11 -05:00
parent 59a25a12ff
commit e00424068f
3 changed files with 11 additions and 0 deletions

View File

@ -70,6 +70,11 @@ namespace StardewModdingAPI.Framework.ModHelpers
public TInterface GetApi<TInterface>(string uniqueID) where TInterface : class
{
// validate
if (!this.Registry.AreAllModsInitialised)
{
this.Monitor.Log("Tried to access a mod-provided API before all mods were initialised.", LogLevel.Error);
return null;
}
if (!typeof(TInterface).IsInterface)
{
this.Monitor.Log("Tried to map a mod-provided API to a class; must be a public interface.", LogLevel.Error);

View File

@ -18,6 +18,9 @@ namespace StardewModdingAPI.Framework
/// <summary>An assembly full name => mod lookup.</summary>
private readonly IDictionary<string, IModMetadata> ModNamesByAssembly = new Dictionary<string, IModMetadata>();
/// <summary>Whether all mods have been initialised and their <see cref="IMod.Entry"/> method called.</summary>
public bool AreAllModsInitialised { get; set; }
/*********
** Public methods

View File

@ -842,6 +842,9 @@ namespace StardewModdingAPI
this.Monitor.Log("Invalidating cached assets for new editors & loaders...", LogLevel.Trace);
this.ContentManager.InvalidateCacheFor(editors, loaders);
}
// unlock mod integrations
this.ModRegistry.AreAllModsInitialised = true;
}
/// <summary>Load a mod's entry class.</summary>