diff options
author | Dan Volchek <volchek2@illinois.edu> | 2018-04-16 03:39:08 -0500 |
---|---|---|
committer | Dan Volchek <volchek2@illinois.edu> | 2018-04-16 03:39:08 -0500 |
commit | 96753c35fd3d6baed73a933c552e5f0a5a8fa02c (patch) | |
tree | d3c3339a3db3624aa38036f0e03fdf9bfb593c0d /src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs | |
parent | d362843706c012867324dc9723e7c7a49a7a2621 (diff) | |
download | SMAPI-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.cs | 19 |
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 { |