Search Results for

    Show / Hide Table of Contents

    Custom Command Validation

    There are two ways you can add additional validation to command calls. One if when a listener is executed, and the other one is before that, which prevents listeners from being invoked altogether. The first way is done by throwing exceptions in the listener callback. The other one uses the CosmosConsole.SetCustomValidator method.

    console.SetCustomValidator("mycommand", ValidateMyCommand);
    

    The second parameter takes a delegate that returns true if the command is valid and can be passed on the the listener callbacks.

    // This command can only be executed on a Sunday (local machine time)
    bool ValidateMyCommand(ICommandSender sender, Command command, out string validationErrorString)
    {
        DayOfWeek day = DateTime.Now.DayOfWeek;
        return (day == DayOfWeek.Sunday);
    }
    

    It's generally recommended to use the SetCustomValidator method over throwing exceptions in the listener callback.

    ☀
    ☾
    In This Article
    Back to top
    © Clavusaurus Game Software
    ☀
    ☾