Simplify argument counting in CommandReader, fix help command duplicating 'unrecognised command' message.

This commit is contained in:
UnknownShadow200 2015-04-25 06:32:48 +10:00
parent 138420c538
commit b3e87d8fb1
2 changed files with 14 additions and 22 deletions

View File

@ -61,7 +61,7 @@ namespace ClassicalSharp.Commands {
public bool NextOf<T>( out T value, TryParseFunc<T> parser ) { public bool NextOf<T>( out T value, TryParseFunc<T> parser ) {
bool success = parser( Next(), out value ); bool success = parser( Next(), out value );
if( !success ) value = default( T); if( !success ) value = default( T );
return success; return success;
} }
@ -76,28 +76,22 @@ namespace ClassicalSharp.Commands {
} }
public int RemainingArgs { public int RemainingArgs {
get { get { return CountArgsFrom( curOffset ); }
int count = 0;
int pos = curOffset;
while( MoveNext() ) {
count++;
}
curOffset = pos;
return count;
}
} }
public int TotalArgs { public int TotalArgs {
get { get { return CountArgsFrom( firstArgOffset ); }
int count = 0; }
int pos = curOffset;
curOffset = firstArgOffset; int CountArgsFrom( int startOffset ) {
while( MoveNext() ) { int count = 0;
count++; int pos = curOffset;
} curOffset = startOffset;
curOffset = pos; while( MoveNext() ) {
return count; count++;
} }
curOffset = pos;
return count;
} }
public void Reset() { public void Reset() {

View File

@ -125,9 +125,7 @@ namespace ClassicalSharp.Commands {
Window.AddChat( "&e/client: &cYou didn't specify a command to get help with." ); Window.AddChat( "&e/client: &cYou didn't specify a command to get help with." );
} else { } else {
Command cmd = Window.CommandManager.GetMatchingCommand( commandName ); Command cmd = Window.CommandManager.GetMatchingCommand( commandName );
if( cmd == null ) { if( cmd != null ) {
Window.AddChat( "&e/client: Unrecognised command: \"&f" + commandName + "&e\"." );
} else {
string[] help = cmd.Help; string[] help = cmd.Help;
for( int i = 0; i < help.Length; i++ ) { for( int i = 0; i < help.Length; i++ ) {
Window.AddChat( help[i] ); Window.AddChat( help[i] );