diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 1901ebb..0aaa1d7 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -291,7 +291,7 @@ minetest.register_chatcommand("/set", { privs = {}, func = worldedit.privs(safe_region(function(name, param) 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 count = worldedit.set(pos1, pos2, node) worldedit.player_notify(name, count .. " nodes set") diff --git a/worldedit_protection/init.lua b/worldedit_protection/init.lua index 9bb8c04..44632cd 100644 --- a/worldedit_protection/init.lua +++ b/worldedit_protection/init.lua @@ -29,11 +29,11 @@ Returns: --privs={worldedit=true [, server=true]} --privs={worldedit=worldedit.priv() [, server=true]} --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 = , --or it can be used directly in an if statement. - if func == nil then - func = function(name, param) end + if privsfunc == nil then + privsfunc = 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. @@ -42,13 +42,13 @@ worldedit.privs = function(--[[name, ]]func--[[, param]]) if minetest.check_player_privs(name, {areas=true}) then --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? - func(name, param) + privsfunc(name, param) return 2 --edit everywhere without checks 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, --worldedit privilege means editing anywhere if minetest.check_player_privs(name, {worldedit=true}) then - func(name, param) + privsfunc(name, param) return 2 --edit everywhere without checks else --func(name, param) placeholder @@ -57,7 +57,7 @@ worldedit.privs = function(--[[name, ]]func--[[, param]]) 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) + privsfunc(name, param) return 1 --edit at least somewhere, with checks end end @@ -69,12 +69,12 @@ end --so the region is defined per-command on exec. --//move has disconnected sections, so it's passed as a list of points. --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 --because func may be removed to have can_edit_volume in an if statement --like worldedit.privs can be - if func == nil then - func = function(name, param) end + if volfunc == nil then + volfunc = function(name, param) end end --worldedit.privs was run once to prevent safe_region large area warnings, @@ -83,59 +83,61 @@ worldedit.can_edit_volume = function(--[[name, ]]volume, func--[[, param]]) --then worldedit.privs is run again to attempt skipping checks (resusing the same code) --then set is finally run. - --worldedit.privs said that 'name' can use worldedit at least somewhere - -- return value 1 (or 2) before this function was run. + return function(name, param) + --worldedit.privs said that 'name' can use worldedit at least somewhere + -- return value 1 (or 2) before this function was run. - --Try skipping volume permission checks. - local wp = worldedit.privs() - if wp == 2 then - func(name, param) - return true - elseif wp == nil then - --safety feature in case worldedit.can_edit_volume is ever run alone, without being surrounded by worldedit.privs() - --Shouldn't ever get here. - --Any volume-changing function is surrounded by this, then safe_region, then worldedit.privs() - --func(name, param) placeholder - return false - end - - --[[I need to use a special per-command region (think /stack, or even worse, /move), the same one safe_region uses, but corner points instead of count... instead of a for loop interpolating between pos1 and pos2]]-- - - --all or nothing here - for i in volume do ---[[ - THIS SECTION IGNORES the distinction of area that is owned by someone else, but still editable - this is treated as area owned by the editor, or no-man's land depending on if it's shared with one person or everyone - - If it was treated differently (it's not), then single edits would not be able to cross the border between someone else's editable land, and no-man's land, to prevent accidental writes. It may cross the border between multiple people's editable land (or should it?), such as to create a bridge between two skyscrapers that were previously built separately. - - This needs testing for the other changes first. ---]] - --Is it owned? - if minetest.is_protected(i) then - --Is it someone else's? - if minetest.is_protected(i, name) then - --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") - --func(name, param) placeholder - return false - end - --it's mine - --continue - - --no-man's land - --can I edit that? - 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)") - --func(name, param) placeholder + --Try skipping volume permission checks. + local wp = worldedit.privs() + if wp == 2 then + volfunc(name, param) + return true + elseif wp == nil then + --safety feature in case worldedit.can_edit_volume is ever run alone, without being surrounded by worldedit.privs() + --Shouldn't ever get here. + --Any volume-changing function is surrounded by this, then safe_region, then worldedit.privs() + --volfunc(name, param) placeholder return false end - end - --the whole thing is - --a) owned by me, and/or - --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) - func(name, param) - return true + --[[I need to use a special per-command region (think /stack, or even worse, /move), the same one safe_region uses, but corner points instead of count... instead of a for loop interpolating between pos1 and pos2]]-- + + --all or nothing here + for i in volume do + --[[ + THIS SECTION IGNORES the distinction of area that is owned by someone else, but still editable + this is treated as area owned by the editor, or no-man's land depending on if it's shared with one person or everyone + + If it was treated differently (it's not), then single edits would not be able to cross the border between someone else's editable land, and no-man's land, to prevent accidental writes. It may cross the border between multiple people's editable land (or should it?), such as to create a bridge between two skyscrapers that were previously built separately. + + This needs testing for the other changes first. + --]] + --Is it owned? + if minetest.is_protected(i) then + --Is it someone else's? + if minetest.is_protected(i, name) then + --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") + --volfunc(name, param) placeholder + return false + end + --it's mine + --continue + + --no-man's land + --can I edit that? + 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)") + --volfunc(name, param) placeholder + return false + end + end + + --the whole thing is + --a) owned by me, and/or + --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) + volfunc(name, param) + return true + end end