Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worldedit Selections (optional) #15

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions depends.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worldedit?
51 changes: 39 additions & 12 deletions pos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,52 @@ minetest.register_chatcommand("area_pos", {
end,
})

function areas.useWorldedit(playerName)
if worldedit then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throws a warning if WorldEdit isn't installed.

if nil == playerName then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

playerName == nil is prefered, but not playerName is even better. This branch isn't used though, so it can just be removed.

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 = 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)
local pos1, pos2 = nil, nil;
if areas.useWorldedit(playerName) then
pos1, pos2 = worldedit.pos1[playerName], worldedit.pos2[playerName];
else
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;
worldedit.mark_pos1(playerName);
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;
worldedit.mark_pos2(playerName);
else
areas.pos2[playerName] = pos
areas.markPos2(playerName)
end
end


Expand Down