From 7e9f841ea0df2eeafa47151300b80f9369b32961 Mon Sep 17 00:00:00 2001 From: Robin Kanters Date: Tue, 5 May 2015 22:55:40 +0200 Subject: [PATCH] Removed regex checking, no functional changes --- TrueCraft/Commands/GiveCommand.cs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/TrueCraft/Commands/GiveCommand.cs b/TrueCraft/Commands/GiveCommand.cs index cb845d2..dccffe7 100644 --- a/TrueCraft/Commands/GiveCommand.cs +++ b/TrueCraft/Commands/GiveCommand.cs @@ -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().First(myMatch => myMatch.Success); - } - catch (InvalidOperationException) - { - return null; - } - } - public override void Help(IRemoteClient client, string alias, string[] arguments) { client.SendMessage("Correct usage is /" + alias + " [Amount]");