yl_cities/priv_example.lua
2025-06-04 23:49:37 +02:00

77 lines
3.0 KiB
Lua

local priv_name = "example"
local priv_definition = {
description = yl_cities.t("privs_example_description"),
-- Privilege description
give_to_singleplayer = false,
-- Whether to grant the privilege to singleplayer.
give_to_admin = true,
-- Whether to grant the privilege to the server admin.
-- Uses value of 'give_to_singleplayer' by default.
on_grant = function(name, granter_name)
-- logging
if (type(granter_name) ~= "string") then
local errormessage = yl_cities.t("error_name_not_found",
dump(granter_name))
yl_cities.log(errormessage)
return false, errormessage
end
if not name then
local errormessage = yl_cities.t("error_name_not_found",
dump(name))
yl_cities.log(errormessage)
return false, errormessage
end
if not priv_name then
local errormessage = yl_cities.t("error_priv_not_found",
dump(priv_name))
yl_cities.log(errormessage)
return false, errormessage
end
local text = yl_cities.t("privs_example_grant_logmessage",
dump(granter_name), dump(priv_name),
dump(name))
yl_cities.log(text)
end,
-- Called when given to player 'name' by 'granter_name'.
-- 'granter_name' will be nil if the priv was granted by a mod.
on_revoke = function(name, revoker_name)
-- logging
if (type(revoker_name) ~= "string") then
local errormessage = yl_cities.t("error_name_not_found",
dump(revoker_name))
yl_cities.log(errormessage)
return false, errormessage
end
if not name then
local errormessage = yl_cities.t("error_name_not_found",
dump(name))
yl_cities.log(errormessage)
return false, errormessage
end
if not priv_name then
local errormessage = yl_cities.t("error_priv_not_found",
dump(priv_name))
yl_cities.log(errormessage)
return false, errormessage
end
local text = yl_cities.t("privs_example_revoke_logmessage",
dump(revoker_name), dump(priv_name),
dump(name))
yl_cities.log(text)
end
-- 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, and then with a nil player
-- name.
-- Return true in the above callbacks to stop register_on_priv_grant or
-- revoke being called.
}
minetest.register_privilege(priv_name, priv_definition)