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.Collections.Generic;
using System.Text;
namespace ClassicalSharp.Commands {
@ -53,7 +54,9 @@ namespace ClassicalSharp.Commands {
public void Execute( string text ) {
CommandReader reader = new CommandReader( text );
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;
}
string commandName = reader.Next();
@ -62,5 +65,24 @@ namespace ClassicalSharp.Commands {
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 ) {
List<string> commandNames = 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 ) {
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 );
}
game.CommandManager.PrintDefinedCommands( game );
}
}
@ -51,7 +36,9 @@ namespace ClassicalSharp.Commands {
public override void Execute( CommandReader reader ) {
string cmdName = reader.Next();
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 {
Command cmd = game.CommandManager.GetMatchingCommand( cmdName );
if( cmd != null ) {