Allow using worldedit.privs() in an if statement
or with a function argument.
This commit is contained in:
parent
4475909a97
commit
4b80eb82cc
|
@ -101,7 +101,7 @@ minetest.register_chatcommand("/inspect", {
|
||||||
minetest.register_on_punchnode(function(pos, node, puncher)
|
minetest.register_on_punchnode(function(pos, node, puncher)
|
||||||
local name = puncher:get_player_name()
|
local name = puncher:get_player_name()
|
||||||
if worldedit.inspect[name] then
|
if worldedit.inspect[name] then
|
||||||
if minetest.check_player_privs(name, {worldedit=true}) then
|
if worldedit.privs() then
|
||||||
local axis, sign = worldedit.player_axis(name)
|
local axis, sign = worldedit.player_axis(name)
|
||||||
message = string.format("inspector: %s at %s (param1=%d, param2=%d) punched by %s facing the %s axis",
|
message = string.format("inspector: %s at %s (param1=%d, param2=%d) punched by %s facing the %s axis",
|
||||||
node.name, minetest.pos_to_string(pos), node.param1, node.param2, name, axis .. (sign > 0 and "+" or "-"))
|
node.name, minetest.pos_to_string(pos), node.param1, node.param2, name, axis .. (sign > 0 and "+" or "-"))
|
||||||
|
|
|
@ -9,11 +9,27 @@ minetest.after(0, function()
|
||||||
--worldedit privilege is permission to edit everything
|
--worldedit privilege is permission to edit everything
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Usage:
|
||||||
|
In chatcommand:
|
||||||
|
privs = {}
|
||||||
|
func = worldedit.privs(function(name, param)...end)
|
||||||
|
|
||||||
|
In if statement:
|
||||||
|
name = minetest.get_player_name(node)
|
||||||
|
if worldedit.privs() then
|
||||||
|
--]]
|
||||||
--I wanted this function to directly choose the privileges for the chat command, but it only applies once.
|
--I wanted this function to directly choose the privileges for the chat command, but it only applies once.
|
||||||
--privs={worldedit=true [, server=true]}
|
--privs={worldedit=true [, server=true]}
|
||||||
--privs={worldedit=worldedit.priv() [, server=true]}
|
--privs={worldedit=worldedit.priv() [, server=true]}
|
||||||
--instead, I had to wrap the rest of func = .
|
--instead, I had to wrap the rest of func = .
|
||||||
worldedit.privs = function(func)
|
worldedit.privs = function(func)
|
||||||
|
--This runs a function for a chatcommand's func = ,
|
||||||
|
--or it can be used directly in an if statement.
|
||||||
|
if func == nil then
|
||||||
|
func = function(name, param) end
|
||||||
|
end
|
||||||
|
|
||||||
--this silly syntax was copied from safe_region, which is actually executed on chatcommand registration, and must return a function instead of the result of a function.
|
--this silly syntax was copied from safe_region, which is actually executed on chatcommand registration, and must return a function instead of the result of a function.
|
||||||
--The innermost anonymous function is declared. Then safe_region executes, adding a function wrapper around that function. Then worldedit.privs gets that as an argument, and adds another wrapper. The doubly-wrapped function is the one registered as a chatcommand.
|
--The innermost anonymous function is declared. Then safe_region executes, adding a function wrapper around that function. Then worldedit.privs gets that as an argument, and adds another wrapper. The doubly-wrapped function is the one registered as a chatcommand.
|
||||||
return function(name, param)
|
return function(name, param)
|
||||||
|
@ -22,13 +38,15 @@ worldedit.privs = function(func)
|
||||||
--worldedit privilege means editing anywhere
|
--worldedit privilege means editing anywhere
|
||||||
if minetest.check_player_privs(name, {worldedit=true}) then
|
if minetest.check_player_privs(name, {worldedit=true}) then
|
||||||
func(name, param)
|
func(name, param)
|
||||||
|
return true
|
||||||
else
|
else
|
||||||
return
|
return false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
--protection mod, can edit inside your area without worldedit privilege
|
--protection mod, can edit inside your area without worldedit privilege
|
||||||
--(worldedit and areas let you edit in no-man's land and other-owned area)
|
--(worldedit and areas let you edit in no-man's land and other-owned area)
|
||||||
func(name, param)
|
func(name, param)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue