From d3b91a2aeb473a2c1fa7eaa35f4c31c0c6566e3e Mon Sep 17 00:00:00 2001 From: Joseph Pickard Date: Sat, 9 Jan 2016 11:30:03 -0500 Subject: [PATCH] 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