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

@ -76,29 +76,23 @@ 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 CountArgsFrom( int startOffset ) {
int count = 0; int count = 0;
int pos = curOffset; int pos = curOffset;
curOffset = firstArgOffset; curOffset = startOffset;
while( MoveNext() ) { while( MoveNext() ) {
count++; count++;
} }
curOffset = pos; curOffset = pos;
return count; return count;
} }
}
public void Reset() { public void Reset() {
curOffset = firstArgOffset; curOffset = firstArgOffset;

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