summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs
diff options
context:
space:
mode:
authorDan Volchek <volchek2@illinois.edu>2018-04-16 03:39:08 -0500
committerDan Volchek <volchek2@illinois.edu>2018-04-16 03:39:08 -0500
commit96753c35fd3d6baed73a933c552e5f0a5a8fa02c (patch)
treed3c3339a3db3624aa38036f0e03fdf9bfb593c0d /src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs
parentd362843706c012867324dc9723e7c7a49a7a2621 (diff)
downloadSMAPI-96753c35fd3d6baed73a933c552e5f0a5a8fa02c.tar.gz
SMAPI-96753c35fd3d6baed73a933c552e5f0a5a8fa02c.tar.bz2
SMAPI-96753c35fd3d6baed73a933c552e5f0a5a8fa02c.zip
add world ready check and more helpful error messages
Diffstat (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs')
-rw-r--r--src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs
index 47ba9e8d..3d55b425 100644
--- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs
+++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs
@@ -32,6 +32,13 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player
/// <param name="args">The command arguments.</param>
public override void Handle(IMonitor monitor, string command, ArgumentParser args)
{
+ // validate
+ if (!Context.IsWorldReady)
+ {
+ monitor.Log("You need to load a save to use this command.", LogLevel.Error);
+ return;
+ }
+
SearchableItem match;
//read arguments
@@ -111,16 +118,22 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player
// find matching items
IEnumerable<SearchableItem> matching = this.Items.GetAll().Where(p => p.DisplayName.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) != -1);
+ SearchableItem exactMatch = matching.FirstOrDefault(item => item.DisplayName.Equals(name, StringComparison.InvariantCultureIgnoreCase));
+
int numberOfMatches = matching.Count();
// handle unique requirement
- if (numberOfMatches == 0)
+ if (exactMatch != null)
{
- monitor.Log($"There's no item with name {name}.", LogLevel.Error);
+ match = matching.ElementAt(0);
+ }
+ else if (numberOfMatches == 0)
+ {
+ monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error);
}
else if (numberOfMatches == 1)
{
- match = matching.ElementAt(0);
+ monitor.Log($"There's no item with name '{name}'. Did you mean '{matching.ElementAt(0).DisplayName}'? If so, type 'player_add name {matching.ElementAt(0).DisplayName}'.", LogLevel.Error);
}
else
{