Files
BetterAmongUs/Commands/BaseCommand.cs
T
D1GQ 200e766054 Anti-cheat handling overhaul.
File Checker rework (from TBR)
Optimized color blind text (from TBR)
Added color coding to console text (from TBR)
2024-12-05 10:21:43 -06:00

47 lines
1.5 KiB
C#

using BetterAmongUs.Helpers;
using System.Reflection;
namespace BetterAmongUs.Commands;
public enum CommandType
{
Normal,
Sponsor,
Debug,
}
public abstract class BaseCommand
{
public static readonly BaseCommand?[] allCommands = GetAllCommandInstances();
public static BaseCommand?[] GetAllCommandInstances() => Assembly.GetExecutingAssembly()
.GetTypes()
.Where(t => t.IsSubclassOf(typeof(BaseCommand)) && !t.IsAbstract)
.Select(t => (BaseCommand)Activator.CreateInstance(t))
.ToArray();
public virtual CommandType Type => CommandType.Normal;
public string[] Names => ShortNames.Concat(new[] { Name }).ToArray();
public abstract string Name { get; }
public virtual string[] ShortNames => [];
public abstract string Description { get; }
public virtual BaseArgument[]? Arguments { get; } = [];
public virtual bool SetChatTimer { get; set; } = false;
public virtual bool ShowCommand() => true;
public virtual bool ShowSuggestion() => ShowCommand();
public abstract void Run();
public static string CommandResultText(string text, bool onlyGetStr = false)
{
if (!onlyGetStr) Utils.AddChatPrivate(text);
return text;
}
public static string CommandErrorText(string error, bool onlyGetStr = false)
{
string er = "<color=#f50000><size=150%><b>Error:</b></size></color>";
if (!onlyGetStr) Utils.AddChatPrivate($"<color=#730000>{er}\n{error}");
return $"<color=#730000>{er}\n{error}";
}
}