From 5e4298d00df6ec3245f7ae06753706bb9b25a074 Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Wed, 21 Jun 2017 12:55:25 +0200 Subject: [PATCH 01/14] basic area protection support --- worldedit_commands/depends.txt | 3 +- worldedit_commands/init.lua | 72 ++++++++++++++++++++++++++++++++-- worldedit_commands/safe.lua | 25 +++++++++++- 3 files changed, 95 insertions(+), 5 deletions(-) diff --git a/worldedit_commands/depends.txt b/worldedit_commands/depends.txt index df8caff..d862cd8 100644 --- a/worldedit_commands/depends.txt +++ b/worldedit_commands/depends.txt @@ -1 +1,2 @@ -worldedit \ No newline at end of file +worldedit +areas? diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 325a31c..654eaa2 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -13,7 +13,7 @@ end dofile(minetest.get_modpath("worldedit_commands") .. "/cuboid.lua") dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua") dofile(minetest.get_modpath("worldedit_commands") .. "/wand.lua") -local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua") +local safe_region, check_region, reset_pending, area_protection = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua") local function get_position(name) --position 1 retrieval function for when not using `safe_region` local pos1 = worldedit.pos1[name] @@ -409,6 +409,13 @@ minetest.register_chatcommand("/mix", { }) local check_replace = function(name, param) + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "check_replace not yet supported with area protection" + ) + return nil + end local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") if found == nil then worldedit.player_notify(name, "invalid usage: " .. param) @@ -456,8 +463,11 @@ minetest.register_chatcommand("/replaceinverse", { }) local check_sphere = function(name, param) - if worldedit.pos1[name] == nil then - worldedit.player_notify(name, "no position 1 selected") + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "check_sphere not yet supported with area protection" + ) return nil end local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") @@ -495,6 +505,13 @@ minetest.register_chatcommand("/sphere", { }) local check_dome = function(name, param) + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "check_dome not yet supported with area protection" + ) + return nil + end if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") return nil @@ -534,6 +551,13 @@ minetest.register_chatcommand("/dome", { }) local check_cylinder = function(name, param) + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "check_cylinder not yet supported with area protection" + ) + return nil + end if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") return nil @@ -583,6 +607,13 @@ minetest.register_chatcommand("/cylinder", { }) local check_pyramid = function(name, param) + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "check_pyramid not yet supported with area protection" + ) + return nil + end if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") return nil @@ -643,6 +674,13 @@ minetest.register_chatcommand("/spiral", { worldedit.player_notify(name, count .. " nodes added") end, function(name, param) + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "/spiral not yet supported with area protection" + ) + return nil + end if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") return nil @@ -766,6 +804,13 @@ minetest.register_chatcommand("/stack2", { worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions, function() worldedit.player_notify(name, count .. " nodes stacked") end) end, function() + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "/stack2 not yet supported with area protection" + ) + return nil + end return count end)(name,param) -- more hax --wip: clean this up a little bit end @@ -791,6 +836,13 @@ minetest.register_chatcommand("/stretch", { worldedit.player_notify(name, count .. " nodes stretched") end, function(name, param) + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "/stretch not yet supported with area protection" + ) + return nil + end local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$") if found == nil then worldedit.player_notify(name, "invalid usage: " .. param) @@ -1071,6 +1123,13 @@ minetest.register_chatcommand("/load", { description = "Load nodes from \"(world folder)/schems/[.we[m]]\" with position 1 of the current WorldEdit region as the origin", privs = {worldedit=true}, func = function(name, param) + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "/load not yet supported with area protection" + ) + return + end local pos = get_position(name) if pos == nil then return end @@ -1187,6 +1246,13 @@ minetest.register_chatcommand("/mtschemplace", { description = "Load nodes from \"(world folder)/schems/.mts\" with position 1 of the current WorldEdit region as the origin", privs = {worldedit=true}, func = function(name, param) + if nil ~= area_protection.areas then + worldedit.player_notify( + name, + "/mtschemplace not yet supported with area protection" + ) + return + end if param == "" then worldedit.player_notify(name, "no filename specified") return diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua index a93e393..7381f4e 100644 --- a/worldedit_commands/safe.lua +++ b/worldedit_commands/safe.lua @@ -1,3 +1,11 @@ +local area_protection = {} + +if minetest.get_modpath( + "areas" +) then + area_protection.areas = areas +end + local safe_region_callback = {} local safe_region_param = {} @@ -7,6 +15,21 @@ local function check_region(name, param) worldedit.player_notify(name, "no region selected") return nil end + if nil ~= area_protection.areas then + local allowed, conflicting = area_protection.areas:canInteractInArea( + pos1, + pos2, + name, + false + ) + if false == allowed then + worldedit.player_notify( + name, + "region conflicts with non-owned region " .. conflicting + ) + return nil + end + end return worldedit.volume(pos1, pos2) end @@ -62,4 +85,4 @@ minetest.register_chatcommand("/n", { }) -return safe_region, check_region, reset_pending +return safe_region, check_region, reset_pending, area_protection From b70a43e31236ca861c61fabcebab31e73f6dbf2a Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Wed, 21 Jun 2017 13:04:54 +0200 Subject: [PATCH 02/14] allow players with areas privilege to use commands where no checking logic is available yet --- worldedit_commands/init.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 654eaa2..ebe537c 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -409,7 +409,7 @@ minetest.register_chatcommand("/mix", { }) local check_replace = function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "check_replace not yet supported with area protection" @@ -463,7 +463,7 @@ minetest.register_chatcommand("/replaceinverse", { }) local check_sphere = function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "check_sphere not yet supported with area protection" @@ -505,7 +505,7 @@ minetest.register_chatcommand("/sphere", { }) local check_dome = function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "check_dome not yet supported with area protection" @@ -551,7 +551,7 @@ minetest.register_chatcommand("/dome", { }) local check_cylinder = function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "check_cylinder not yet supported with area protection" @@ -607,7 +607,7 @@ minetest.register_chatcommand("/cylinder", { }) local check_pyramid = function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "check_pyramid not yet supported with area protection" @@ -674,7 +674,7 @@ minetest.register_chatcommand("/spiral", { worldedit.player_notify(name, count .. " nodes added") end, function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "/spiral not yet supported with area protection" @@ -804,7 +804,7 @@ minetest.register_chatcommand("/stack2", { worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions, function() worldedit.player_notify(name, count .. " nodes stacked") end) end, function() - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "/stack2 not yet supported with area protection" @@ -836,7 +836,7 @@ minetest.register_chatcommand("/stretch", { worldedit.player_notify(name, count .. " nodes stretched") end, function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "/stretch not yet supported with area protection" @@ -1123,7 +1123,7 @@ minetest.register_chatcommand("/load", { description = "Load nodes from \"(world folder)/schems/[.we[m]]\" with position 1 of the current WorldEdit region as the origin", privs = {worldedit=true}, func = function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "/load not yet supported with area protection" @@ -1246,7 +1246,7 @@ minetest.register_chatcommand("/mtschemplace", { description = "Load nodes from \"(world folder)/schems/.mts\" with position 1 of the current WorldEdit region as the origin", privs = {worldedit=true}, func = function(name, param) - if nil ~= area_protection.areas then + if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then worldedit.player_notify( name, "/mtschemplace not yet supported with area protection" From 734a4d3bd13bd86d6a997286e51e0aab544c58ae Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Wed, 21 Jun 2017 18:25:45 +0200 Subject: [PATCH 03/14] sphere conflict detection --- worldedit_commands/init.lua | 38 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index ebe537c..f511bf1 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -409,13 +409,6 @@ minetest.register_chatcommand("/mix", { }) local check_replace = function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then - worldedit.player_notify( - name, - "check_replace not yet supported with area protection" - ) - return nil - end local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") if found == nil then worldedit.player_notify(name, "invalid usage: " .. param) @@ -463,18 +456,35 @@ minetest.register_chatcommand("/replaceinverse", { }) local check_sphere = function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then - worldedit.player_notify( - name, - "check_sphere not yet supported with area protection" - ) - return nil - end local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") if found == nil then worldedit.player_notify(name, "invalid usage: " .. param) return nil end + if nil ~= area_protection.areas then + local pos1 = worldedit.pos1[name] + local allowed, conflicting = area_protection.areas:canInteractInArea( + { + x = pos1.x - radius, + y = pos1.y - radius, + z = pos1.z - radius, + }, + { + x = pos1.x + radius, + y = pos1.y + radius, + z = pos1.z + radius, + }, + name, + false + ) + if false == allowed then + worldedit.player_notify( + name, + "sphere may conflict with non-owned region " .. conflicting + ) + return nil + end + end local node = get_node(name, nodename) if not node then return nil end return math.ceil((4 * math.pi * (tonumber(radius) ^ 3)) / 3) --volume of sphere From 8dbccb004f77c6e520db818b6182c5eadf2f286f Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Thu, 22 Jun 2017 02:05:17 +0200 Subject: [PATCH 04/14] dome conflict detection --- worldedit_commands/init.lua | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index f511bf1..bc1c141 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -515,13 +515,6 @@ minetest.register_chatcommand("/sphere", { }) local check_dome = function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then - worldedit.player_notify( - name, - "check_dome not yet supported with area protection" - ) - return nil - end if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") return nil @@ -531,6 +524,30 @@ local check_dome = function(name, param) worldedit.player_notify(name, "invalid usage: " .. param) return nil end + if nil ~= area_protection.areas then + local pos1 = worldedit.pos1[name] + local allowed, conflicting = area_protection.areas:canInteractInArea( + { + x = pos1.x - radius, + y = pos1.y, + z = pos1.z - radius, + }, + { + x = pos1.x + radius, + y = pos1.y + radius, + z = pos1.z + radius, + }, + name, + false + ) + if false == allowed then + worldedit.player_notify( + name, + "dome may conflict with non-owned region " .. conflicting + ) + return nil + end + end local node = get_node(name, nodename) if not node then return nil end return math.ceil((2 * math.pi * (tonumber(radius) ^ 3)) / 3) --volume of dome From 7166c89f02dd8416b7a602b1380b743d52d4ab2f Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Wed, 28 Jun 2017 18:17:58 +0200 Subject: [PATCH 05/14] cylinder conflict detection --- worldedit_commands/init.lua | 49 +++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index bc1c141..fceb91a 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -578,13 +578,6 @@ minetest.register_chatcommand("/dome", { }) local check_cylinder = function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then - worldedit.player_notify( - name, - "check_cylinder not yet supported with area protection" - ) - return nil - end if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") return nil @@ -594,6 +587,48 @@ local check_cylinder = function(name, param) worldedit.player_notify(name, "invalid usage: " .. param) return nil end + if nil ~= area_protection.areas then + if axis == "?" then + local sign + axis, sign = worldedit.player_axis(name) + length = length * sign + end + local pos1 = worldedit.pos1[name] + local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z} + if length < 0 then + length = -length + current_pos[axis] = current_pos[axis] - length + end + local other1, other2 = worldedit.get_axis_others(axis) + local interact_pos1 = { + x = current_pos.x, + y = current_pos.y, + z = current_pos.z, + } + local interact_pos2 = { + x = current_pos.x, + y = current_pos.y, + z = current_pos.z, + } + interact_pos1[other1] = interact_pos1[other1] - radius + interact_pos1[other2] = interact_pos1[other2] - radius + interact_pos2[other1] = interact_pos2[other1] + radius + interact_pos2[other2] = interact_pos2[other2] + radius + interact_pos2[axis] = interact_pos2[axis] + length + local allowed, conflicting = area_protection.areas:canInteractInArea( + interact_pos1, + interact_pos2, + name, + false + ) + if false == allowed then + worldedit.player_notify( + name, + "cylinder may conflict with non-owned region " .. conflicting + ) + return nil + end + end local node = get_node(name, nodename) if not node then return nil end return math.ceil(math.pi * (tonumber(radius) ^ 2) * tonumber(length)) From 337c1e6d27c1240bc1f4f73882a658f7a6233348 Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Wed, 28 Jun 2017 18:32:17 +0200 Subject: [PATCH 06/14] restore accidentally removed check --- worldedit_commands/init.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index fceb91a..40155f0 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -456,6 +456,10 @@ minetest.register_chatcommand("/replaceinverse", { }) local check_sphere = function(name, param) + if worldedit.pos1[name] == nil then + worldedit.player_notify(name, "no position 1 selected") + return nil + end local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") if found == nil then worldedit.player_notify(name, "invalid usage: " .. param) From 1da3b32dbedf4380a3eff549435292f8cb7bc29f Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Wed, 28 Jun 2017 18:36:18 +0200 Subject: [PATCH 07/14] adapt style --- worldedit_commands/safe.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua index 7381f4e..f6a359b 100644 --- a/worldedit_commands/safe.lua +++ b/worldedit_commands/safe.lua @@ -1,8 +1,6 @@ local area_protection = {} -if minetest.get_modpath( - "areas" -) then +if minetest.get_modpath("areas") then area_protection.areas = areas end From 3de6cdcf8411d1b86f3bca05eb2c4f9036d714ed Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Wed, 28 Jun 2017 19:09:56 +0200 Subject: [PATCH 08/14] fix type error --- worldedit_commands/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 40155f0..ac6db3b 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -592,6 +592,7 @@ local check_cylinder = function(name, param) return nil end if nil ~= area_protection.areas then + length = tonumber(length) if axis == "?" then local sign axis, sign = worldedit.player_axis(name) From 19c9ca179b25bdd2f36d1490a6891589f5dbb5d9 Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Sat, 1 Jul 2017 10:23:51 +0200 Subject: [PATCH 09/14] move logic to method --- worldedit_commands/init.lua | 158 ++++++++++++++++-------------------- worldedit_commands/safe.lua | 47 +++++++---- 2 files changed, 103 insertions(+), 102 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index ac6db3b..a2bb8fb 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -465,29 +465,23 @@ local check_sphere = function(name, param) worldedit.player_notify(name, "invalid usage: " .. param) return nil end - if nil ~= area_protection.areas then - local pos1 = worldedit.pos1[name] - local allowed, conflicting = area_protection.areas:canInteractInArea( - { - x = pos1.x - radius, - y = pos1.y - radius, - z = pos1.z - radius, - }, - { - x = pos1.x + radius, - y = pos1.y + radius, - z = pos1.z + radius, - }, - name, - false - ) - if false == allowed then - worldedit.player_notify( - name, - "sphere may conflict with non-owned region " .. conflicting - ) - return nil - end + local pos1 = worldedit.pos1[name] + local allowed = area_protection:interaction_allowed( + "sphere", + { + x = pos1.x - radius, + y = pos1.y - radius, + z = pos1.z - radius, + }, + { + x = pos1.x + radius, + y = pos1.y + radius, + z = pos1.z + radius, + }, + name + ) + if not allowed then + return nil end local node = get_node(name, nodename) if not node then return nil end @@ -528,29 +522,23 @@ local check_dome = function(name, param) worldedit.player_notify(name, "invalid usage: " .. param) return nil end - if nil ~= area_protection.areas then - local pos1 = worldedit.pos1[name] - local allowed, conflicting = area_protection.areas:canInteractInArea( - { - x = pos1.x - radius, - y = pos1.y, - z = pos1.z - radius, - }, - { - x = pos1.x + radius, - y = pos1.y + radius, - z = pos1.z + radius, - }, - name, - false - ) - if false == allowed then - worldedit.player_notify( - name, - "dome may conflict with non-owned region " .. conflicting - ) - return nil - end + local pos1 = worldedit.pos1[name] + local allowed = area_protection:interaction_allowed( + "dome", + { + x = pos1.x - radius, + y = pos1.y, + z = pos1.z - radius, + }, + { + x = pos1.x + radius, + y = pos1.y + radius, + z = pos1.z + radius, + }, + name + ) + if not allowed then + return nil end local node = get_node(name, nodename) if not node then return nil end @@ -591,48 +579,42 @@ local check_cylinder = function(name, param) worldedit.player_notify(name, "invalid usage: " .. param) return nil end - if nil ~= area_protection.areas then - length = tonumber(length) - if axis == "?" then - local sign - axis, sign = worldedit.player_axis(name) - length = length * sign - end - local pos1 = worldedit.pos1[name] - local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z} - if length < 0 then - length = -length - current_pos[axis] = current_pos[axis] - length - end - local other1, other2 = worldedit.get_axis_others(axis) - local interact_pos1 = { - x = current_pos.x, - y = current_pos.y, - z = current_pos.z, - } - local interact_pos2 = { - x = current_pos.x, - y = current_pos.y, - z = current_pos.z, - } - interact_pos1[other1] = interact_pos1[other1] - radius - interact_pos1[other2] = interact_pos1[other2] - radius - interact_pos2[other1] = interact_pos2[other1] + radius - interact_pos2[other2] = interact_pos2[other2] + radius - interact_pos2[axis] = interact_pos2[axis] + length - local allowed, conflicting = area_protection.areas:canInteractInArea( - interact_pos1, - interact_pos2, - name, - false - ) - if false == allowed then - worldedit.player_notify( - name, - "cylinder may conflict with non-owned region " .. conflicting - ) - return nil - end + length = tonumber(length) + if axis == "?" then + local sign + axis, sign = worldedit.player_axis(name) + length = length * sign + end + local pos1 = worldedit.pos1[name] + local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z} + if length < 0 then + length = -length + current_pos[axis] = current_pos[axis] - length + end + local other1, other2 = worldedit.get_axis_others(axis) + local interact_pos1 = { + x = current_pos.x, + y = current_pos.y, + z = current_pos.z, + } + local interact_pos2 = { + x = current_pos.x, + y = current_pos.y, + z = current_pos.z, + } + interact_pos1[other1] = interact_pos1[other1] - radius + interact_pos1[other2] = interact_pos1[other2] - radius + interact_pos2[other1] = interact_pos2[other1] + radius + interact_pos2[other2] = interact_pos2[other2] + radius + interact_pos2[axis] = interact_pos2[axis] + length + local allowed = area_protection:interaction_allowed( + "cylinder", + interact_pos1, + interact_pos2, + name + ) + if not allowed then + return nil end local node = get_node(name, nodename) if not node then return nil end diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua index f6a359b..d4ac454 100644 --- a/worldedit_commands/safe.lua +++ b/worldedit_commands/safe.lua @@ -4,6 +4,31 @@ if minetest.get_modpath("areas") then area_protection.areas = areas end +local area_protection.interaction_allowed = function( + area_protection, + description, + pos1, + pos2, + player_name +) + if area_protection.areas then + local allowed, conflicting = area_protection.areas:canInteractInArea( + pos1, + pos2, + player_name, + false + ) + if not allowed then + worldedit.player_notify( + player_name, + description .. " conflicts with non-owned region " .. conflicting + ) + end + return allowed + end + return true +end + local safe_region_callback = {} local safe_region_param = {} @@ -13,20 +38,14 @@ local function check_region(name, param) worldedit.player_notify(name, "no region selected") return nil end - if nil ~= area_protection.areas then - local allowed, conflicting = area_protection.areas:canInteractInArea( - pos1, - pos2, - name, - false - ) - if false == allowed then - worldedit.player_notify( - name, - "region conflicts with non-owned region " .. conflicting - ) - return nil - end + local allowed = area_protection:interaction_allowed( + "region", + pos1, + pos2, + name + ) + if not allowed then + return nil end return worldedit.volume(pos1, pos2) end From 443614f7045f5cdc8d6fa645c1935705146b1a7e Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Sat, 1 Jul 2017 10:31:46 +0200 Subject: [PATCH 10/14] move logic to method --- worldedit_commands/init.lua | 12 ++++++------ worldedit_commands/safe.lua | 13 +++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index a2bb8fb..d00c47c 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -656,7 +656,7 @@ minetest.register_chatcommand("/cylinder", { }) local check_pyramid = function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then + if area_protection:interaction_restrictions(name) then worldedit.player_notify( name, "check_pyramid not yet supported with area protection" @@ -723,7 +723,7 @@ minetest.register_chatcommand("/spiral", { worldedit.player_notify(name, count .. " nodes added") end, function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then + if area_protection:interaction_restrictions(name) then worldedit.player_notify( name, "/spiral not yet supported with area protection" @@ -853,7 +853,7 @@ minetest.register_chatcommand("/stack2", { worldedit.stack2(pos1, pos2, {x=x, y=y, z=z}, repetitions, function() worldedit.player_notify(name, count .. " nodes stacked") end) end, function() - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then + if area_protection:interaction_restrictions(name) then worldedit.player_notify( name, "/stack2 not yet supported with area protection" @@ -885,7 +885,7 @@ minetest.register_chatcommand("/stretch", { worldedit.player_notify(name, count .. " nodes stretched") end, function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then + if area_protection:interaction_restrictions(name) then worldedit.player_notify( name, "/stretch not yet supported with area protection" @@ -1172,7 +1172,7 @@ minetest.register_chatcommand("/load", { description = "Load nodes from \"(world folder)/schems/[.we[m]]\" with position 1 of the current WorldEdit region as the origin", privs = {worldedit=true}, func = function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then + if area_protection:interaction_restrictions(name) then worldedit.player_notify( name, "/load not yet supported with area protection" @@ -1295,7 +1295,7 @@ minetest.register_chatcommand("/mtschemplace", { description = "Load nodes from \"(world folder)/schems/.mts\" with position 1 of the current WorldEdit region as the origin", privs = {worldedit=true}, func = function(name, param) - if nil ~= area_protection.areas and not minetest.check_player_privs(name, {areas = true}) then + if area_protection:interaction_restrictions(name) then worldedit.player_notify( name, "/mtschemplace not yet supported with area protection" diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua index d4ac454..96fa00a 100644 --- a/worldedit_commands/safe.lua +++ b/worldedit_commands/safe.lua @@ -4,6 +4,19 @@ if minetest.get_modpath("areas") then area_protection.areas = areas end +local area_protection.interaction_restrictions = function( + area_protection, + player_name +) + if area_protection.areas then + if minetest.check_player_privs(name, {areas = true}) then + return false + end + return true + end + return false +end + local area_protection.interaction_allowed = function( area_protection, description, From 97fc580bbf60cdeede18c63fa64bcf565ee110e1 Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Mon, 3 Jul 2017 13:38:59 +0200 Subject: [PATCH 11/14] pyramid support --- worldedit_commands/init.lua | 39 ++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index d00c47c..5d21e40 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -656,13 +656,6 @@ minetest.register_chatcommand("/cylinder", { }) local check_pyramid = function(name, param) - if area_protection:interaction_restrictions(name) then - worldedit.player_notify( - name, - "check_pyramid not yet supported with area protection" - ) - return nil - end if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") return nil @@ -672,6 +665,38 @@ local check_pyramid = function(name, param) worldedit.player_notify(name, "invalid usage: " .. param) return nil end + height = tonumber(height) + if axis == "?" then + local sign + axis, sign = worldedit.player_axis(name) + height = height * sign + end + local pos1 = worldedit.pos1[name] + local other1, other2 = worldedit.get_axis_others(axis) + local interact_pos1 = { + x = pos1.x, + y = pos1.y, + z = pos1.z, + } + local interact_pos2 = { + x = pos1.x, + y = pos1.y, + z = pos1.z, + } + interact_pos1[other1] = interact_pos1[other1] - height + interact_pos1[other2] = interact_pos1[other2] - height + interact_pos2[other1] = interact_pos2[other1] + height + interact_pos2[other2] = interact_pos2[other2] + height + interact_pos2[axis] = interact_pos2[axis] + height + local allowed = area_protection:interaction_allowed( + "pyramid", + interact_pos1, + interact_pos2, + name + ) + if not allowed then + return nil + end local node = get_node(name, nodename) if not node then return nil end height = tonumber(height) From 840f5e8c1f5de7b28b570d05cb84a969494c6606 Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Mon, 3 Jul 2017 13:46:10 +0200 Subject: [PATCH 12/14] fix slot access syntax --- worldedit_commands/safe.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua index 96fa00a..520f875 100644 --- a/worldedit_commands/safe.lua +++ b/worldedit_commands/safe.lua @@ -4,7 +4,7 @@ if minetest.get_modpath("areas") then area_protection.areas = areas end -local area_protection.interaction_restrictions = function( +area_protection.interaction_restrictions = function( area_protection, player_name ) @@ -17,7 +17,7 @@ local area_protection.interaction_restrictions = function( return false end -local area_protection.interaction_allowed = function( +area_protection.interaction_allowed = function( area_protection, description, pos1, From 6174196b50ddc1bc0ae3e2607a1a3d8aa245c847 Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Sat, 11 Nov 2017 18:03:56 +0100 Subject: [PATCH 13/14] bugfix --- worldedit_commands/safe.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua index 520f875..ee956b4 100644 --- a/worldedit_commands/safe.lua +++ b/worldedit_commands/safe.lua @@ -9,7 +9,12 @@ area_protection.interaction_restrictions = function( player_name ) if area_protection.areas then - if minetest.check_player_privs(name, {areas = true}) then + if minetest.check_player_privs( + player_name, + { + areas = true + } + ) then return false end return true From 9a789c66361fbeab04f10b50ea83b639485b911b Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Mon, 1 Jan 2018 16:42:22 +0100 Subject: [PATCH 14/14] simplify using vector helper function --- worldedit_commands/init.lua | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 5d21e40..9e714ec 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -585,23 +585,14 @@ local check_cylinder = function(name, param) axis, sign = worldedit.player_axis(name) length = length * sign end - local pos1 = worldedit.pos1[name] - local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z} + local current_pos = vector.new(worldedit.pos1[name]) if length < 0 then length = -length current_pos[axis] = current_pos[axis] - length end local other1, other2 = worldedit.get_axis_others(axis) - local interact_pos1 = { - x = current_pos.x, - y = current_pos.y, - z = current_pos.z, - } - local interact_pos2 = { - x = current_pos.x, - y = current_pos.y, - z = current_pos.z, - } + local interact_pos1 = vector.new(current_pos) + local interact_pos2 = vector.new(current_pos) interact_pos1[other1] = interact_pos1[other1] - radius interact_pos1[other2] = interact_pos1[other2] - radius interact_pos2[other1] = interact_pos2[other1] + radius @@ -673,16 +664,8 @@ local check_pyramid = function(name, param) end local pos1 = worldedit.pos1[name] local other1, other2 = worldedit.get_axis_others(axis) - local interact_pos1 = { - x = pos1.x, - y = pos1.y, - z = pos1.z, - } - local interact_pos2 = { - x = pos1.x, - y = pos1.y, - z = pos1.z, - } + local interact_pos1 = vector.new(pos1) + local interact_pos2 = vector.new(pos1) interact_pos1[other1] = interact_pos1[other1] - height interact_pos1[other2] = interact_pos1[other2] - height interact_pos2[other1] = interact_pos2[other1] + height