summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-06-19 19:01:28 -0400
committerGitHub <noreply@github.com>2018-06-19 19:01:28 -0400
commit92bfc32e685da067a5cfb5a24bad162eebce50d3 (patch)
treec971870558b5f4b5274c0e256f132173352a97d5 /src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player
parent5abc20953e91d03041d40dd7c55dd104a59116c6 (diff)
parent580fd687b0f676b9ddac3ee7938b4e0ac5a987c3 (diff)
downloadSMAPI-92bfc32e685da067a5cfb5a24bad162eebce50d3.tar.gz
SMAPI-92bfc32e685da067a5cfb5a24bad162eebce50d3.tar.bz2
SMAPI-92bfc32e685da067a5cfb5a24bad162eebce50d3.zip
Merge pull request #542 from danvolchek/exact-add-command
[Console Commands] Add command finds item by name when there is exactly one exact match
Diffstat (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player')
-rw-r--r--src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs
index 71c3ff98..5bc97225 100644
--- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs
+++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Player/AddCommand.cs
@@ -100,6 +100,12 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player
// find matching items
SearchableItem[] matches = this.Items.GetAll().Where(p => p.NameContains(name)).ToArray();
+
+ // if exactly one item with the exact same name, use that item
+ SearchableItem[] exactNameMatches = matches.Where(p => p.NameEquivalentTo(name)).ToArray();
+ if (exactNameMatches.Length == 1)
+ return exactNameMatches[0];
+
switch (matches.Length)
{
// none found
@@ -107,10 +113,6 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Player
monitor.Log($"There's no item with name '{name}'. You can use the 'list_items [name]' command to search for items.", LogLevel.Error);
return null;
- // exact match
- case 1 when matches[0].NameEquivalentTo(name):
- return matches[0];
-
// list matches
default:
string options = this.GetTableString(