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 ) {
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() {

View File

@ -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] );