From b3e87d8fb108b1a59d90431210cc9b23e7cd08da Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 25 Apr 2015 06:32:48 +1000 Subject: [PATCH] Simplify argument counting in CommandReader, fix help command duplicating 'unrecognised command' message. --- Commands/CommandReader.cs | 32 +++++++++++++------------------- Commands/DefaultCommands.cs | 4 +--- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Commands/CommandReader.cs b/Commands/CommandReader.cs index d84bad819..f09ff9160 100644 --- a/Commands/CommandReader.cs +++ b/Commands/CommandReader.cs @@ -61,7 +61,7 @@ namespace ClassicalSharp.Commands { public bool NextOf( out T value, TryParseFunc parser ) { bool success = parser( Next(), out value ); - if( !success ) value = default( T); + if( !success ) value = default( T ); return success; } @@ -76,28 +76,22 @@ namespace ClassicalSharp.Commands { } public int RemainingArgs { - get { - int count = 0; - int pos = curOffset; - while( MoveNext() ) { - count++; - } - curOffset = pos; - return count; - } + get { return CountArgsFrom( curOffset ); } } public int TotalArgs { - get { - int count = 0; - int pos = curOffset; - curOffset = firstArgOffset; - while( MoveNext() ) { - count++; - } - curOffset = pos; - return count; + get { return CountArgsFrom( firstArgOffset ); } + } + + int CountArgsFrom( int startOffset ) { + int count = 0; + int pos = curOffset; + curOffset = startOffset; + while( MoveNext() ) { + count++; } + curOffset = pos; + return count; } public void Reset() { diff --git a/Commands/DefaultCommands.cs b/Commands/DefaultCommands.cs index 45f4f05f6..e7a4b9dd5 100644 --- a/Commands/DefaultCommands.cs +++ b/Commands/DefaultCommands.cs @@ -125,9 +125,7 @@ namespace ClassicalSharp.Commands { Window.AddChat( "&e/client: &cYou didn't specify a command to get help with." ); } else { Command cmd = Window.CommandManager.GetMatchingCommand( commandName ); - if( cmd == null ) { - Window.AddChat( "&e/client: Unrecognised command: \"&f" + commandName + "&e\"." ); - } else { + if( cmd != null ) { string[] help = cmd.Help; for( int i = 0; i < help.Length; i++ ) { Window.AddChat( help[i] );