mirror of
https://github.com/rafi1212122/BLHX.Server.git
synced 2025-12-13 23:14:57 +01:00
Command system and input system
This commit is contained in:
32
BLHX.Server.Game/Commands/HelpCommand.cs
Normal file
32
BLHX.Server.Game/Commands/HelpCommand.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace BLHX.Server.Game.Commands;
|
||||
|
||||
[commandHandler("help", "Print out all commands with their description and example", "help")]
|
||||
public class HelpCommand : Command
|
||||
{
|
||||
static readonly Dictionary<Type, commandHandler?> commandAttributes = new Dictionary<Type, commandHandler?>();
|
||||
|
||||
public override void Execute(Dictionary<string, string> args)
|
||||
{
|
||||
base.Execute(args);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine("Available Commands: ");
|
||||
foreach (var command in CommandHandler.Commands)
|
||||
{
|
||||
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})");
|
||||
}
|
||||
|
||||
Console.Write(sb.ToString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user