diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index d6a5e05..884bb16 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -101,7 +101,7 @@ minetest.register_chatcommand("/inspect", { minetest.register_on_punchnode(function(pos, node, puncher) local name = puncher:get_player_name() 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) 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 "-")) diff --git a/worldedit_protection/init.lua b/worldedit_protection/init.lua index 4ee2ea3..2cefc50 100644 --- a/worldedit_protection/init.lua +++ b/worldedit_protection/init.lua @@ -9,11 +9,27 @@ minetest.after(0, function() --worldedit privilege is permission to edit everything 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. --privs={worldedit=true [, server=true]} --privs={worldedit=worldedit.priv() [, server=true]} --instead, I had to wrap the rest of 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. --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) @@ -22,13 +38,15 @@ worldedit.privs = function(func) --worldedit privilege means editing anywhere if minetest.check_player_privs(name, {worldedit=true}) then func(name, param) + return true else - return + return false end else --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) func(name, param) + return true end end end