moreblocks/invsaw/privs.lua

51 lines
1.3 KiB
Lua
Raw Normal View History

2022-06-20 00:34:08 +02:00
-- luacheck: globals minetest
2022-06-20 00:26:05 +02:00
local creative_priv = invsaw.settings.creative_priv
local priv = invsaw.settings.priv
local function on_priv_change(name)
local player = minetest.get_player_by_name(name)
if player then
2022-06-20 00:34:08 +02:00
invsaw.check_use_status(player)
2022-06-20 00:26:05 +02:00
end
end
2022-06-20 02:08:21 +02:00
local function override_on_priv_change(old)
return function(name, cause)
2022-06-20 00:26:05 +02:00
on_priv_change(name)
2022-06-20 02:08:21 +02:00
if old then
old(name, cause)
2022-06-20 00:26:05 +02:00
end
end
2022-06-20 02:08:21 +02:00
end
if minetest.registered_privileges[priv] then
local def = minetest.registered_privileges[priv]
def.on_grant = override_on_priv_change(def.on_grant)
def.on_revoke = override_on_priv_change(def.on_revoke)
2022-06-20 00:26:05 +02:00
else
minetest.register_privilege(priv, {
description = "Allow use of the circular saw in inventory",
give_to_singleplayer = true,
give_to_admin = false,
on_grant = on_priv_change,
on_revoke = on_priv_change,
})
end
if minetest.registered_privileges[creative_priv] then
local def = minetest.registered_privileges[creative_priv]
2022-06-20 02:08:21 +02:00
def.on_grant = override_on_priv_change(def.on_grant)
def.on_revoke = override_on_priv_change(def.on_revoke)
2022-06-20 00:26:05 +02:00
else
minetest.register_privilege(creative_priv, {
description = "Allow use of the inventory saw creatively",
give_to_singleplayer = true,
give_to_admin = false,
on_grant = on_priv_change,
on_revoke = on_priv_change,
})
end