Print more helpful message for /client and /client help (Thanks FabTheZen)

This commit is contained in:
UnknownShadow200 2015-11-29 22:54:32 +11:00
parent 4f01d562d0
commit 18ca858e87
2 changed files with 27 additions and 18 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace ClassicalSharp.Commands { namespace ClassicalSharp.Commands {
@ -53,7 +54,9 @@ namespace ClassicalSharp.Commands {
public void Execute( string text ) { public void Execute( string text ) {
CommandReader reader = new CommandReader( text ); CommandReader reader = new CommandReader( text );
if( reader.TotalArgs == 0 ) { if( reader.TotalArgs == 0 ) {
game.Chat.Add( "&e/client: No command name specified. See /client commands for a list of commands." ); game.Chat.Add( "&eList of client commands:" );
PrintDefinedCommands( game );
game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" );
return; return;
} }
string commandName = reader.Next(); string commandName = reader.Next();
@ -62,5 +65,24 @@ namespace ClassicalSharp.Commands {
cmd.Execute( reader ); cmd.Execute( reader );
} }
} }
public void PrintDefinedCommands( Game game ) {
List<string> lines = new List<string>();
StringBuilder buffer = new StringBuilder( 64 );
foreach( Command cmd in game.CommandManager.RegisteredCommands ) {
string name = cmd.Name;
if( buffer.Length + name.Length > 64 ) {
lines.Add( buffer.ToString() );
buffer.Length = 0;
}
buffer.Append( name );
buffer.Append( ", " );
}
if( buffer.Length > 0 )
lines.Add( buffer.ToString() );
foreach( string part in lines ) {
game.Chat.Add( part );
}
}
} }
} }

View File

@ -18,22 +18,7 @@ namespace ClassicalSharp.Commands {
} }
public override void Execute( CommandReader reader ) { public override void Execute( CommandReader reader ) {
List<string> commandNames = new List<string>(); game.CommandManager.PrintDefinedCommands( game );
StringBuilder buffer = new StringBuilder( 64 );
foreach( Command cmd in game.CommandManager.RegisteredCommands ) {
string name = cmd.Name;
if( buffer.Length + name.Length > 64 ) {
commandNames.Add( buffer.ToString() );
buffer.Length = 0;
}
buffer.Append( name + ", " );
}
if( buffer.Length > 0 ) {
commandNames.Add( buffer.ToString() );
}
foreach( string part in commandNames ) {
game.Chat.Add( part );
}
} }
} }
@ -51,7 +36,9 @@ namespace ClassicalSharp.Commands {
public override void Execute( CommandReader reader ) { public override void Execute( CommandReader reader ) {
string cmdName = reader.Next(); string cmdName = reader.Next();
if( cmdName == null ) { if( cmdName == null ) {
game.Chat.Add( "&e/client help: No command name specified. See /client commands for a list of commands." ); game.Chat.Add( "&eList of client commands:" );
game.CommandManager.PrintDefinedCommands( game );
game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" );
} else { } else {
Command cmd = game.CommandManager.GetMatchingCommand( cmdName ); Command cmd = game.CommandManager.GetMatchingCommand( cmdName );
if( cmd != null ) { if( cmd != null ) {