summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Command.cs39
-rw-r--r--src/StardewModdingAPI/Constants.cs2
2 files changed, 22 insertions, 19 deletions
diff --git a/src/StardewModdingAPI/Command.cs b/src/StardewModdingAPI/Command.cs
index 17924c08..65207f0e 100644
--- a/src/StardewModdingAPI/Command.cs
+++ b/src/StardewModdingAPI/Command.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using StardewModdingAPI.Events;
namespace StardewModdingAPI
@@ -68,29 +69,31 @@ namespace StardewModdingAPI
/****
** SMAPI
****/
- /// <summary>Invoke the specified command.</summary>
+ /// <summary>Parse a command string and invoke it if valid.</summary>
/// <param name="input">The command to run, including the command name and any arguments.</param>
public static void CallCommand(string input)
{
- input = input.TrimEnd(' ');
- string[] args = new string[0];
- Command command;
- if (input.Contains(" "))
- {
- args = input.Split(new[] { " " }, 2, StringSplitOptions.RemoveEmptyEntries);
- command = Command.FindCommand(args[0]);
- args = args[1].Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
- }
- else
- command = Command.FindCommand(input);
+ // normalise input
+ input = input?.Trim();
+ if (string.IsNullOrWhiteSpace(input))
+ return;
+
+ // tokenise input
+ string[] args = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
+ string commandName = args[0];
+ args = args.Skip(1).ToArray();
- if (command != null)
+ // get command
+ Command command = Command.FindCommand(commandName);
+ if (command == null)
{
- command.CalledArgs = args;
- command.Fire();
- }
- else
Log.AsyncR("Unknown command");
+ return;
+ }
+
+ // fire command
+ command.CalledArgs = args;
+ command.Fire();
}
/// <summary>Register a command with SMAPI.</summary>
@@ -118,4 +121,4 @@ namespace StardewModdingAPI
return Command.RegisteredCommands.Find(x => x.CommandName.Equals(name));
}
}
-} \ No newline at end of file
+}
diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs
index 12496cbf..6c6d8868 100644
--- a/src/StardewModdingAPI/Constants.cs
+++ b/src/StardewModdingAPI/Constants.cs
@@ -23,7 +23,7 @@ namespace StardewModdingAPI
** Accessors
*********/
/// <summary>SMAPI's current semantic version.</summary>
- public static readonly Version Version = new Version(1, 0, 0, "beta2");
+ public static readonly Version Version = new Version(1, 0, 0, "beta3");
/// <summary>The minimum supported version of Stardew Valley.</summary>
public const string MinimumGameVersion = "1.1";