Skip to content

Commit 72c09f5

Browse files
rubenwardynerzhul
authored andcommittedAug 29, 2017
Fix mistake when calling on_priv_grant/revoke, and document them (#6341)
1 parent 2bd1a31 commit 72c09f5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

Diff for: ‎builtin/game/register.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ end
437437

438438
function core.run_priv_callbacks(name, priv, caller, method)
439439
if not core.registered_privileges[priv]["on_" .. method] or
440-
core.registered_privileges[priv]["on_" .. method](name, caller) then
440+
not core.registered_privileges[priv]["on_" .. method](name, caller) then
441441
for _, func in ipairs(core["registered_on_priv_" .. method]) do
442-
if not func(name, caller) then
442+
if not func(name, caller, priv) then
443443
break
444444
end
445445
end

Diff for: ‎doc/lua_api.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,14 @@ Call these functions only at load time!
24472447
* `minetest.register_on_item_eat(func(hp_change, replace_with_item, itemstack, user, pointed_thing))`
24482448
* Called when an item is eaten, by `minetest.item_eat`
24492449
* Return `true` or `itemstack` to cancel the default item eat response (i.e.: hp increase)
2450+
* `minetest.register_on_priv_grant(function(name, granter, priv))`
2451+
* Called when `granter` grants the priv `priv` to `name`.
2452+
* Note that the callback will be called twice if it's done by a player, once with granter being the player name,
2453+
and again with granter being nil.
2454+
* `minetest.register_on_priv_revoke(function(name, revoker, priv))`
2455+
* Called when `revoker` revokes the priv `priv` from `name`.
2456+
* Note that the callback will be called twice if it's done by a player, once with revoker being the player name,
2457+
and again with revoker being nil.
24502458

24512459
### Other registration functions
24522460
* `minetest.register_chatcommand(cmd, chatcommand definition)`
@@ -2464,8 +2472,9 @@ Call these functions only at load time!
24642472
`granter_name` will be nil if the priv was granted by a mod.
24652473
* `on_revoke(name, revoker_name)`: Called when taken from player `name` by `revoker_name`.
24662474
`revoker_name` will be nil if the priv was revoked by a mod
2467-
* Note that the above two callbacks will be called twice if a player is responsible -
2475+
* Note that the above two callbacks will be called twice if a player is responsible -
24682476
once with the player name, and then with a nil player name.
2477+
* Return true in the above callbacks to stop register_on_priv_grant or revoke being called.
24692478
* `minetest.register_authentication_handler(handler)`
24702479
* See `minetest.builtin_auth_handler` in `builtin.lua` for reference
24712480

0 commit comments

Comments
 (0)
Please sign in to comment.