evaera / Cmdr

Extensible command console for Roblox developers
https://eryn.io/Cmdr/
MIT License
363 stars 104 forks source link

Add command-specific guard methods #291

Closed itsrenderman closed 1 year ago

itsrenderman commented 1 year ago

Closes #86

Example usage:

return {
    -- <insert command object here with name, aliases, description, etc.>

    Guards = {
        function(self)
            if math.random(1,3) == 2 then
                return "You are unlucky!"
            end
        end;
        function(self)
            return if self.Executor.UserId ~= 92658764 then "You are not allowed to do this!" else nil
        end;
    };
}
autonordev commented 1 year ago

Guard methods are checked before hooks

Out of curiosity can you explain why you decided to do it this way?

itsrenderman commented 1 year ago

Guard methods are checked before hooks

Out of curiosity can you explain why you decided to do it this way?

I interpreted the initial proposal with the idea that guards should have a higher potency on the outcome of command execution over hooks

autonordev commented 1 year ago

Hey, thanks for the contribution. We've discussed this internally and think that hooks should run before guards, this is because hooks are more 'generic'. For instance, if a player lacks the permissions to run a command, that is more important than an argument needing to have a player whose character health is above 0.

Are you willing to make this adjustment yourself? If not, that's completely fine since I can do it.

itsrenderman commented 1 year ago

Quickly changed this on phone, should be good now 👍