Repository navigation
Requirement checkers
In this system you can add requirement checks to all the commands you want. For example if you want to add "admin only" commands, you can create a requirement checker and add it to the methods or even the whole class. Every requirement checker will run in the main thread, so don't worry about using AltAsync.Do.
The requirement checker is your own custom attribute which overrides the "CustomCommandRequirementBase" attribute.
So to create one, you need to create an attribute and implement the "CanExecute" method.
Example for admin level checker:
class NeedAdminLevelCheckerAttribute : CustomCommandRequirementBaseAttribute
{
public int AdminLevelNeeded { get; set; }
public NeedAdminLevelCheckerAttribute(int adminLevelNeeded) => AdminLevelNeeded = adminLevelNeeded;
public override bool CanExecute(IPlayer player, CustomCommandInfo? info, ArraySegment<object?> methodArgs)
{
var playerAdminLevel = player.GetData<int>("AdminLevel");
return playerAdminLevel >= AdminLevelNeeded;
}
}You can now use this attribute either on a class or a method.
If you add it to a class, every method in that class will have this requirement checker.
You can also combine the requirement checkers, e.g. have methods with 10 checkers, no problem.
[NeedAdminLevelChecker(1)]
class SupporterCommands
{
[CustomCommand("kick")]
void Kick(IPlayer player, IPlayer target) { }
[CustomCommand("spectate")]
void Spectate(IPlayer player, IPlayer target) { }
}class AllCommands
{
[CustomCommand("kick")]
[NeedAdminLevelChecker(1)]
void Kick(IPlayer player, IPlayer target) { }
[CustomCommand("ban")]
[NeedAdminLevelChecker(2)]
void Ban(IPlayer player, IPlayer target, int time) { }
}