extending command for user and prevent err in build ship menu

This commit is contained in:
rfi
2024-02-22 21:22:48 +07:00
parent db93c8f49d
commit bdc8785fe1
8 changed files with 133 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
using System.Reflection;
using BLHX.Server.Game.Handlers;
using System.Reflection;
using System.Text;
namespace BLHX.Server.Game.Commands;
@@ -15,7 +16,29 @@ public class HelpCommand : Command
StringBuilder sb = new StringBuilder();
sb.AppendLine("Available Commands: ");
foreach (var command in CommandHandlerFactory.Commands)
foreach (var command in CommandHandlerFactory.Commands.Where(x => x.Usage.HasFlag(CommandUsage.Console)))
{
if (!commandAttributes.TryGetValue(command.GetType(), out var attr))
{
attr = command.GetType().GetCustomAttribute(typeof(CommandHandler)) as CommandHandler;
commandAttributes[command.GetType()] = attr;
}
if (attr != null)
sb.AppendLine($" {attr.Name} - {attr.Description} (Example: {attr.Example}), Usage: {command.Usage}");
}
Console.Write(sb.ToString());
}
public override void Execute(Dictionary<string, string> args, Connection connection)
{
base.Execute(args);
StringBuilder sb = new StringBuilder();
sb.AppendLine("Available Commands: ");
foreach (var command in CommandHandlerFactory.Commands.Where(x => x.Usage.HasFlag(CommandUsage.User)))
{
if (!commandAttributes.TryGetValue(command.GetType(), out var attr))
{
@@ -27,6 +50,6 @@ public class HelpCommand : Command
sb.AppendLine($" {attr.Name} - {attr.Description} (Example: {attr.Example})");
}
Console.Write(sb.ToString());
connection.SendSystemMsg(sb.ToString());
}
}