summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/DeprecationManager.cs31
-rw-r--r--src/SMAPI/Framework/ModHelpers/CommandHelper.cs8
2 files changed, 20 insertions, 19 deletions
diff --git a/src/SMAPI/Framework/DeprecationManager.cs b/src/SMAPI/Framework/DeprecationManager.cs
index 94a2da85..c22b5718 100644
--- a/src/SMAPI/Framework/DeprecationManager.cs
+++ b/src/SMAPI/Framework/DeprecationManager.cs
@@ -35,19 +35,17 @@ namespace StardewModdingAPI.Framework
this.ModRegistry = modRegistry;
}
- /// <summary>Log a deprecation warning for the old-style events.</summary>
- public void WarnForOldEvents()
+ /// <summary>Get the source name for a mod from its unique ID.</summary>
+ public string GetSourceNameFromStack()
{
- this.Warn("legacy events", "2.9", DeprecationLevel.PendingRemoval);
+ return this.ModRegistry.GetFromStack()?.DisplayName;
}
- /// <summary>Log a deprecation warning.</summary>
- /// <param name="nounPhrase">A noun phrase describing what is deprecated.</param>
- /// <param name="version">The SMAPI version which deprecated it.</param>
- /// <param name="severity">How deprecated the code is.</param>
- public void Warn(string nounPhrase, string version, DeprecationLevel severity)
+ /// <summary>Get the source name for a mod from its unique ID.</summary>
+ /// <param name="modId">The mod's unique ID.</param>
+ public string GetSourceName(string modId)
{
- this.Warn(this.ModRegistry.GetFromStack()?.DisplayName, nounPhrase, version, severity);
+ return this.ModRegistry.Get(modId)?.DisplayName;
}
/// <summary>Log a deprecation warning.</summary>
@@ -58,7 +56,7 @@ namespace StardewModdingAPI.Framework
public void Warn(string source, string nounPhrase, string version, DeprecationLevel severity)
{
// ignore if already warned
- if (!this.MarkWarned(source ?? "<unknown>", nounPhrase, version))
+ if (!this.MarkWarned(source ?? this.GetSourceNameFromStack() ?? "<unknown>", nounPhrase, version))
return;
// queue warning
@@ -111,21 +109,16 @@ namespace StardewModdingAPI.Framework
this.QueuedWarnings.Clear();
}
- /// <summary>Mark a deprecation warning as already logged.</summary>
- /// <param name="nounPhrase">A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method").</param>
- /// <param name="version">The SMAPI version which deprecated it.</param>
- /// <returns>Returns whether the deprecation was successfully marked as warned. Returns <c>false</c> if it was already marked.</returns>
- public bool MarkWarned(string nounPhrase, string version)
- {
- return this.MarkWarned(this.ModRegistry.GetFromStack()?.DisplayName, nounPhrase, version);
- }
+ /*********
+ ** Private methods
+ *********/
/// <summary>Mark a deprecation warning as already logged.</summary>
/// <param name="source">The friendly name of the assembly which used the deprecated code.</param>
/// <param name="nounPhrase">A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method").</param>
/// <param name="version">The SMAPI version which deprecated it.</param>
/// <returns>Returns whether the deprecation was successfully marked as warned. Returns <c>false</c> if it was already marked.</returns>
- public bool MarkWarned(string source, string nounPhrase, string version)
+ private bool MarkWarned(string source, string nounPhrase, string version)
{
if (string.IsNullOrWhiteSpace(source))
throw new InvalidOperationException("The deprecation source cannot be empty.");
diff --git a/src/SMAPI/Framework/ModHelpers/CommandHelper.cs b/src/SMAPI/Framework/ModHelpers/CommandHelper.cs
index 600f867f..69382009 100644
--- a/src/SMAPI/Framework/ModHelpers/CommandHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/CommandHelper.cs
@@ -36,8 +36,16 @@ namespace StardewModdingAPI.Framework.ModHelpers
}
/// <inheritdoc />
+ [Obsolete]
public bool Trigger(string name, string[] arguments)
{
+ SCore.DeprecationManager.Warn(
+ source: SCore.DeprecationManager.GetSourceName(this.ModID),
+ nounPhrase: $"{nameof(IModHelper)}.{nameof(IModHelper.ConsoleCommands)}.{nameof(ICommandHelper.Trigger)}",
+ version: "3.8.1",
+ severity: DeprecationLevel.Notice
+ );
+
return this.CommandManager.Trigger(name, arguments);
}
}