New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add on_grant and on_revoke callbacks #4713
Conversation
Add “Update Unified Inventory main buttons” to the list of use cases. :-) I like the concept (I am generally in favor of new callbacks) and say “Thank you!”. |
e0aeb2f
to
579bf07
Compare
579bf07
to
3087d2d
Compare
Currently callbacks being called twice, once with the player name and once without. I don't think it's that bad, and it's hard to fix cleanly. Alternatively, I could do on_player_grant etc and then it would call each callback at most once. |
builtin/game/auth.lua
Outdated
print("Running callback!") | ||
if not core.registered_privileges[priv].on_grant | ||
or core.registered_privileges[priv].on_grant(name, nil) then | ||
for _, func in ipairs(core.registered_on_priv_grant) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dup code, please factorize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix dup code and reduce code indent with functions and i'm okay
doc/lua_api.txt
Outdated
`granter_name` will be nil if the priv was granted by a mod. | ||
* `on_revoke(name, revoker_name)`: Called when taken from player `name` by `revoker_name`. | ||
`revoker_name` will be nil if the priv was revoked by a mod | ||
* Note that the above two callbacks will be called twice if a player is responsible - once with the player name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unusual long line. Mind moving more to the second one?
Tested, works. You've got some debugging leftovers, which also need to be removed before merge. |
3087d2d
to
7be4a87
Compare
updated. I think I'm going to split the callback in two - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay for me
* Add register_on_priv_grant/revoke, and on_grant/revoke to privs. Call from /grant and /revoke * Call on_grant and on_revoke callbacks from set_privs
* Add register_on_priv_grant/revoke, and on_grant/revoke to privs. Call from /grant and /revoke * Call on_grant and on_revoke callbacks from set_privs
* Add register_on_priv_grant/revoke, and on_grant/revoke to privs. Call from /grant and /revoke * Call on_grant and on_revoke callbacks from set_privs
The second commit makes it work with mods generally, however the callbacks are called twice when doing /grant - once for when doing set_privs, the other from the /grant function.
USE CASES
TODO