mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-07-03 16:40:38 +02:00
copy .privs with .can_edit_volume for a function wrapper
as well as a conditional for good measure.
This commit is contained in:
@ -291,7 +291,7 @@ minetest.register_chatcommand("/set", {
|
|||||||
privs = {},
|
privs = {},
|
||||||
func = worldedit.privs(safe_region(function(name, param)
|
func = worldedit.privs(safe_region(function(name, param)
|
||||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
if worldedit.can_edit_volume(area:iterp(pos1, pos2)) then
|
if worldedit.can_edit_volume(VoxelArea:iterp(pos1, pos2)) then
|
||||||
local node = get_node(name, param)
|
local node = get_node(name, param)
|
||||||
local count = worldedit.set(pos1, pos2, node)
|
local count = worldedit.set(pos1, pos2, node)
|
||||||
worldedit.player_notify(name, count .. " nodes set")
|
worldedit.player_notify(name, count .. " nodes set")
|
||||||
|
@ -29,11 +29,11 @@ Returns:
|
|||||||
--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(--[[name, ]]func--[[, param]])
|
worldedit.privs = function(--[[name, ]]privsfunc--[[, param]])
|
||||||
--This runs a function for a chatcommand's func = ,
|
--This runs a function for a chatcommand's func = ,
|
||||||
--or it can be used directly in an if statement.
|
--or it can be used directly in an if statement.
|
||||||
if func == nil then
|
if privsfunc == nil then
|
||||||
func = function(name, param) end
|
privsfunc = function(name, param) end
|
||||||
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.
|
||||||
@ -42,13 +42,13 @@ worldedit.privs = function(--[[name, ]]func--[[, param]])
|
|||||||
if minetest.check_player_privs(name, {areas=true}) then
|
if minetest.check_player_privs(name, {areas=true}) then
|
||||||
--You can set areas, so you are allowed to worldedit them too.
|
--You can set areas, so you are allowed to worldedit them too.
|
||||||
--The ability to set the whole world as owned by yourself is already potentially destructive, what's more destructive capability?
|
--The ability to set the whole world as owned by yourself is already potentially destructive, what's more destructive capability?
|
||||||
func(name, param)
|
privsfunc(name, param)
|
||||||
return 2 --edit everywhere without checks
|
return 2 --edit everywhere without checks
|
||||||
elseif not minetest.setting_getbool("creative_mode") or not PROTECTION_MOD_EXISTS then
|
elseif not minetest.setting_getbool("creative_mode") or not PROTECTION_MOD_EXISTS then
|
||||||
--no protection mod, or not the kind of world where people can just create nodes out of thin air,
|
--no protection mod, or not the kind of world where people can just create nodes out of thin air,
|
||||||
--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)
|
privsfunc(name, param)
|
||||||
return 2 --edit everywhere without checks
|
return 2 --edit everywhere without checks
|
||||||
else
|
else
|
||||||
--func(name, param) placeholder
|
--func(name, param) placeholder
|
||||||
@ -57,7 +57,7 @@ worldedit.privs = function(--[[name, ]]func--[[, param]])
|
|||||||
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)
|
privsfunc(name, param)
|
||||||
return 1 --edit at least somewhere, with checks
|
return 1 --edit at least somewhere, with checks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -69,12 +69,12 @@ end
|
|||||||
--so the region is defined per-command on exec.
|
--so the region is defined per-command on exec.
|
||||||
--//move has disconnected sections, so it's passed as a list of points.
|
--//move has disconnected sections, so it's passed as a list of points.
|
||||||
--which are deduplicated.
|
--which are deduplicated.
|
||||||
worldedit.can_edit_volume = function(--[[name, ]]volume, func--[[, param]])
|
worldedit.can_edit_volume = function(--[[name, ]]volume, volfunc--[[, param]])
|
||||||
--volume is before func, unlike safe_region having func before count
|
--volume is before func, unlike safe_region having func before count
|
||||||
--because func may be removed to have can_edit_volume in an if statement
|
--because func may be removed to have can_edit_volume in an if statement
|
||||||
--like worldedit.privs can be
|
--like worldedit.privs can be
|
||||||
if func == nil then
|
if volfunc == nil then
|
||||||
func = function(name, param) end
|
volfunc = function(name, param) end
|
||||||
end
|
end
|
||||||
|
|
||||||
--worldedit.privs was run once to prevent safe_region large area warnings,
|
--worldedit.privs was run once to prevent safe_region large area warnings,
|
||||||
@ -83,19 +83,20 @@ worldedit.can_edit_volume = function(--[[name, ]]volume, func--[[, param]])
|
|||||||
--then worldedit.privs is run again to attempt skipping checks (resusing the same code)
|
--then worldedit.privs is run again to attempt skipping checks (resusing the same code)
|
||||||
--then set is finally run.
|
--then set is finally run.
|
||||||
|
|
||||||
|
return function(name, param)
|
||||||
--worldedit.privs said that 'name' can use worldedit at least somewhere
|
--worldedit.privs said that 'name' can use worldedit at least somewhere
|
||||||
-- return value 1 (or 2) before this function was run.
|
-- return value 1 (or 2) before this function was run.
|
||||||
|
|
||||||
--Try skipping volume permission checks.
|
--Try skipping volume permission checks.
|
||||||
local wp = worldedit.privs()
|
local wp = worldedit.privs()
|
||||||
if wp == 2 then
|
if wp == 2 then
|
||||||
func(name, param)
|
volfunc(name, param)
|
||||||
return true
|
return true
|
||||||
elseif wp == nil then
|
elseif wp == nil then
|
||||||
--safety feature in case worldedit.can_edit_volume is ever run alone, without being surrounded by worldedit.privs()
|
--safety feature in case worldedit.can_edit_volume is ever run alone, without being surrounded by worldedit.privs()
|
||||||
--Shouldn't ever get here.
|
--Shouldn't ever get here.
|
||||||
--Any volume-changing function is surrounded by this, then safe_region, then worldedit.privs()
|
--Any volume-changing function is surrounded by this, then safe_region, then worldedit.privs()
|
||||||
--func(name, param) placeholder
|
--volfunc(name, param) placeholder
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -117,7 +118,7 @@ worldedit.can_edit_volume = function(--[[name, ]]volume, func--[[, param]])
|
|||||||
if minetest.is_protected(i, name) then
|
if minetest.is_protected(i, name) then
|
||||||
--already checked the ability to make it mine (areas)
|
--already checked the ability to make it mine (areas)
|
||||||
minetest.chat_send_player(name, "Someone else owns at least part of what you want to edit")
|
minetest.chat_send_player(name, "Someone else owns at least part of what you want to edit")
|
||||||
--func(name, param) placeholder
|
--volfunc(name, param) placeholder
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
--it's mine
|
--it's mine
|
||||||
@ -127,7 +128,7 @@ worldedit.can_edit_volume = function(--[[name, ]]volume, func--[[, param]])
|
|||||||
--can I edit that?
|
--can I edit that?
|
||||||
elseif not minetest.check_player_privs(name, {worldedit=true}) then --cache this check?
|
elseif not minetest.check_player_privs(name, {worldedit=true}) then --cache this check?
|
||||||
minetest.chat_send_player(name, "You can only edit area in which you own a plot (missing worldedit privilege)")
|
minetest.chat_send_player(name, "You can only edit area in which you own a plot (missing worldedit privilege)")
|
||||||
--func(name, param) placeholder
|
--volfunc(name, param) placeholder
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -136,6 +137,7 @@ worldedit.can_edit_volume = function(--[[name, ]]volume, func--[[, param]])
|
|||||||
--a) owned by me, and/or
|
--a) owned by me, and/or
|
||||||
--b) owned by no one and I have the worldedit privilege.
|
--b) owned by no one and I have the worldedit privilege.
|
||||||
--c) I have the areas privilege and it's possibly owned by someone else. (returned earlier)
|
--c) I have the areas privilege and it's possibly owned by someone else. (returned earlier)
|
||||||
func(name, param)
|
volfunc(name, param)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
Reference in New Issue
Block a user