Removed regex checking, no functional changes

This commit is contained in:
Robin Kanters 2015-05-05 22:55:40 +02:00
parent d567a538fe
commit 7e9f841ea0

View File

@ -26,18 +26,18 @@ namespace TrueCraft.Commands
public override void Handle(IRemoteClient client, string alias, string[] arguments)
{
var regexMatch = GetValuesFromArguments(arguments);
if (regexMatch == null)
if (arguments.Length < 3)
{
Help(client, alias, arguments);
return;
}
string username = regexMatch.Groups[1].ToString(),
itemid = regexMatch.Groups[2].ToString(),
amount = regexMatch.Groups[4].ToString(); // match 3 is the amount with the leading space
string username = arguments[1],
itemid = arguments[2],
amount = "1";
if (String.IsNullOrEmpty(amount)) amount = "1"; // default to 1 when amount is omitted
if(arguments.Length >= 4)
amount = arguments[3];
var receivingPlayer =
client.Server.Clients.FirstOrDefault(c => String.Equals(c.Username, username, StringComparison.CurrentCultureIgnoreCase));
@ -78,19 +78,6 @@ namespace TrueCraft.Commands
}
}
private Match GetValuesFromArguments(string[] arguments)
{
try
{
var myRegex = new Regex(@"^give ([a-zA-Z0-9_\.]+) ([0-9]+)( ([0-9]+))?$", RegexOptions.IgnoreCase);
return myRegex.Matches(String.Join(" ", arguments)).Cast<Match>().First(myMatch => myMatch.Success);
}
catch (InvalidOperationException)
{
return null;
}
}
public override void Help(IRemoteClient client, string alias, string[] arguments)
{
client.SendMessage("Correct usage is /" + alias + " <User> <Item ID> [Amount]");