From d3b91a2aeb473a2c1fa7eaa35f4c31c0c6566e3e Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sat, 9 Jan 2016 11:30:03 -0500 Subject: [PATCH 1/8] Added optional worldedit dependency and used it for selection. --- depends.txt | 1 + pos.lua | 45 +++++++++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 depends.txt diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..c4f6871 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +worldedit? diff --git a/pos.lua b/pos.lua index 8d3e6fe..4ae6900 100644 --- a/pos.lua +++ b/pos.lua @@ -118,25 +118,46 @@ minetest.register_chatcommand("area_pos", { end, }) +function areas.useWorldedit(playerName) + if minetest.get_modpath("worldedit") then + return nil == playerName or minetest.check_player_privs(playerName, "worldedit"); + else + return false; + end +end + function areas:getPos(playerName) - local pos1, pos2 = areas.pos1[playerName], areas.pos2[playerName] - if not (pos1 and pos2) then - return nil - end - -- Copy positions so that the area table doesn't contain multiple - -- references to the same position. - pos1, pos2 = vector.new(pos1), vector.new(pos2) - return areas:sortPos(pos1, pos2) + if areas.useWorldedit(playerName) then + local pos1, pos2 = worldedit.pos1[playerName], worldedit.pos2[playerName]; + else + local pos1, pos2 = areas.pos1[playerName], areas.pos2[playerName]; + end + + if not (pos1 and pos2) then + return nil + end + -- Copy positions so that the area table doesn't contain multiple + -- references to the same position. + pos1, pos2 = vector.new(pos1), vector.new(pos2) + return areas:sortPos(pos1, pos2) end function areas:setPos1(playerName, pos) - areas.pos1[playerName] = pos - areas.markPos1(playerName) + if areas.useWorldedit(playerName) then + worldedit.pos1[playerName] = pos; + else + areas.pos1[playerName] = pos + areas.markPos1(playerName) + end end function areas:setPos2(playerName, pos) - areas.pos2[playerName] = pos - areas.markPos2(playerName) + if areas.useWorldedit(playerName) then + worldedit.pos2[playerName] = pos; + else + areas.pos2[playerName] = pos + areas.markPos2(playerName) + end end From 7a400bb1b99bd1475c834cb1a189cbffaa2695f6 Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sun, 10 Jan 2016 13:24:22 -0500 Subject: [PATCH 2/8] Fixed useWorldedit function. --- pos.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pos.lua b/pos.lua index 4ae6900..9b91755 100644 --- a/pos.lua +++ b/pos.lua @@ -120,7 +120,7 @@ minetest.register_chatcommand("area_pos", { function areas.useWorldedit(playerName) if minetest.get_modpath("worldedit") then - return nil == playerName or minetest.check_player_privs(playerName, "worldedit"); + return nil == playerName or minetest.check_player_privs(playerName, {worldedit = true}); else return false; end From 2dc928a7bfd0165656de9a4ff646ecb68cc6d84f Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sun, 10 Jan 2016 13:56:11 -0500 Subject: [PATCH 3/8] --- pos.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pos.lua b/pos.lua index 9b91755..1f60532 100644 --- a/pos.lua +++ b/pos.lua @@ -119,8 +119,12 @@ minetest.register_chatcommand("area_pos", { }) function areas.useWorldedit(playerName) - if minetest.get_modpath("worldedit") then - return nil == playerName or minetest.check_player_privs(playerName, {worldedit = true}); + if minetest or minetest.get_modpath("worldedit") then + if nil == playerName then + return true; + elseif minetest.check_player_privs(playerName, {worldedit = true}) then + return true; + end else return false; end From c2fafceb861e66e6aee016cdeb2d02381b11eba8 Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sun, 10 Jan 2016 15:41:41 -0500 Subject: [PATCH 4/8] --- pos.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pos.lua b/pos.lua index 1f60532..3f19da0 100644 --- a/pos.lua +++ b/pos.lua @@ -119,7 +119,7 @@ minetest.register_chatcommand("area_pos", { }) function areas.useWorldedit(playerName) - if minetest or minetest.get_modpath("worldedit") then + if worldedit or minetest.get_modpath("worldedit") then if nil == playerName then return true; elseif minetest.check_player_privs(playerName, {worldedit = true}) then From 6bba3ad79438bbaeb4db009a06cf7706f20e4250 Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sun, 10 Jan 2016 15:51:15 -0500 Subject: [PATCH 5/8] --- pos.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pos.lua b/pos.lua index 3f19da0..0baec92 100644 --- a/pos.lua +++ b/pos.lua @@ -119,22 +119,22 @@ minetest.register_chatcommand("area_pos", { }) function areas.useWorldedit(playerName) - if worldedit or minetest.get_modpath("worldedit") then + if worldedit then if nil == playerName then return true; elseif minetest.check_player_privs(playerName, {worldedit = true}) then return true; end - else - return false; end + return false; end function areas:getPos(playerName) + local pos1, pos2 = nil, nil; if areas.useWorldedit(playerName) then - local pos1, pos2 = worldedit.pos1[playerName], worldedit.pos2[playerName]; + pos1, pos2 = worldedit.pos1[playerName], worldedit.pos2[playerName]; else - local pos1, pos2 = areas.pos1[playerName], areas.pos2[playerName]; + pos1, pos2 = areas.pos1[playerName], areas.pos2[playerName]; end if not (pos1 and pos2) then From f77d7743eb8bbe57706283fb9c815e43b7a432ae Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sun, 10 Jan 2016 15:56:06 -0500 Subject: [PATCH 6/8] Fix problem with setting worldedit selection. --- pos.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pos.lua b/pos.lua index 0baec92..8c2f664 100644 --- a/pos.lua +++ b/pos.lua @@ -149,6 +149,7 @@ end function areas:setPos1(playerName, pos) if areas.useWorldedit(playerName) then worldedit.pos1[playerName] = pos; + worldedit.mark_pos1(name); else areas.pos1[playerName] = pos areas.markPos1(playerName) @@ -158,6 +159,7 @@ end function areas:setPos2(playerName, pos) if areas.useWorldedit(playerName) then worldedit.pos2[playerName] = pos; + worldedit.mark_pos2(name); else areas.pos2[playerName] = pos areas.markPos2(playerName) From 609ad76a519f349f5bc01bc899bb67a97b3a7e98 Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sun, 10 Jan 2016 16:01:04 -0500 Subject: [PATCH 7/8] Fixed a typo. --- pos.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pos.lua b/pos.lua index 8c2f664..7c85731 100644 --- a/pos.lua +++ b/pos.lua @@ -149,7 +149,7 @@ end function areas:setPos1(playerName, pos) if areas.useWorldedit(playerName) then worldedit.pos1[playerName] = pos; - worldedit.mark_pos1(name); + worldedit.mark_pos1(playerName); else areas.pos1[playerName] = pos areas.markPos1(playerName) @@ -159,7 +159,7 @@ end function areas:setPos2(playerName, pos) if areas.useWorldedit(playerName) then worldedit.pos2[playerName] = pos; - worldedit.mark_pos2(name); + worldedit.mark_pos2(playerName); else areas.pos2[playerName] = pos areas.markPos2(playerName) From a7df7000faccf8502ec5f53525c2d269926ec911 Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sun, 7 Feb 2016 11:24:56 -0500 Subject: [PATCH 8/8] Removed semicolons. All access to the area positions are now done through functions. --- pos.lua | 64 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/pos.lua b/pos.lua index 7c85731..60aae87 100644 --- a/pos.lua +++ b/pos.lua @@ -11,6 +11,17 @@ areas.set_pos = {} areas.pos1 = {} areas.pos2 = {} +function areas.useWorldedit(playerName) + if nil ~= worldedit then + if nil == playerName then + return true + elseif minetest.check_player_privs(playerName, {worldedit = true}) then + return true + end + end + return false +end + minetest.register_chatcommand("select_area", { params = "", description = "Select a area by id.", @@ -101,13 +112,13 @@ minetest.register_chatcommand("area_pos", { return true, "Select position 2 by punching a node." elseif param == "get" then -- Display current area positions local pos1str, pos2str = "Position 1: ", "Position 2: " - if areas.pos1[name] then - pos1str = pos1str..minetest.pos_to_string(areas.pos1[name]) + if nil ~= areas:getPos1(name) then + pos1str = pos1str..minetest.pos_to_string(areas:getPos1(name)) else pos1str = pos1str.."" end - if areas.pos2[name] then - pos2str = pos2str..minetest.pos_to_string(areas.pos2[name]) + if nil ~= areas:getPos2(name) then + pos2str = pos2str..minetest.pos_to_string(areas:getPos2(name)) else pos2str = pos2str.."" end @@ -117,24 +128,13 @@ minetest.register_chatcommand("area_pos", { end end, }) - -function areas.useWorldedit(playerName) - if worldedit then - if nil == playerName then - return true; - elseif minetest.check_player_privs(playerName, {worldedit = true}) then - return true; - end - end - return false; -end function areas:getPos(playerName) - local pos1, pos2 = nil, nil; + local pos1, pos2 = nil, nil if areas.useWorldedit(playerName) then - pos1, pos2 = worldedit.pos1[playerName], worldedit.pos2[playerName]; + pos1, pos2 = worldedit.pos1[playerName], worldedit.pos2[playerName] else - pos1, pos2 = areas.pos1[playerName], areas.pos2[playerName]; + pos1, pos2 = areas.pos1[playerName], areas.pos2[playerName] end if not (pos1 and pos2) then @@ -146,10 +146,20 @@ function areas:getPos(playerName) return areas:sortPos(pos1, pos2) end +function areas:getPos1(playerName) + local pos1, pos2 = areas:getPos(playerName) + return pos1 +end + +function areas:getPos2(playerName) + local pos1, pos2 = areas:getPos(playerName) + return pos2 +end + function areas:setPos1(playerName, pos) if areas.useWorldedit(playerName) then - worldedit.pos1[playerName] = pos; - worldedit.mark_pos1(playerName); + worldedit.pos1[playerName] = pos + worldedit.mark_pos1(playerName) else areas.pos1[playerName] = pos areas.markPos1(playerName) @@ -158,8 +168,8 @@ end function areas:setPos2(playerName, pos) if areas.useWorldedit(playerName) then - worldedit.pos2[playerName] = pos; - worldedit.mark_pos2(playerName); + worldedit.pos2[playerName] = pos + worldedit.mark_pos2(playerName) else areas.pos2[playerName] = pos areas.markPos2(playerName) @@ -172,21 +182,21 @@ minetest.register_on_punchnode(function(pos, node, puncher) -- Currently setting position if name ~= "" and areas.set_pos[name] then if areas.set_pos[name] == "pos1" then - areas.pos1[name] = pos + areas:setPos1(name, pos) areas.markPos1(name) areas.set_pos[name] = "pos2" minetest.chat_send_player(name, "Position 1 set to " ..minetest.pos_to_string(pos)) elseif areas.set_pos[name] == "pos1only" then - areas.pos1[name] = pos + areas:pos1(name, pos) areas.markPos1(name) areas.set_pos[name] = nil minetest.chat_send_player(name, "Position 1 set to " ..minetest.pos_to_string(pos)) elseif areas.set_pos[name] == "pos2" then - areas.pos2[name] = pos + areas:setPos2(name, pos) areas.markPos2(name) areas.set_pos[name] = nil minetest.chat_send_player(name, @@ -214,7 +224,7 @@ end -- Marks area position 1 areas.markPos1 = function(name) - local pos = areas.pos1[name] + local pos = areas.getPos1(name) if areas.marker1[name] ~= nil then -- Marker already exists areas.marker1[name]:remove() -- Remove marker areas.marker1[name] = nil @@ -227,7 +237,7 @@ end -- Marks area position 2 areas.markPos2 = function(name) - local pos = areas.pos2[name] + local pos = areas.getPos2(name) if areas.marker2[name] ~= nil then -- Marker already exists areas.marker2[name]:remove() -- Remove marker areas.marker2[name] = nil