forked from minetest-mods/areas
1a5efd07f1
In other words, you can retain ownership of an area but disable and re-enable the protection aspect at will, via the area_open chat command. By default, nothing is any different following this commit - all existing areas are protected, as are new ones. But you can do (for example) "area_open 1" and if you're the owner of that area, it's now possible for other users to interact there. "area_open 1" again to toggle the protection back on. Where there are sub-areas, the main owner and ALL sub-area owners at a particulare location must have set the areas to open to disable protection.
44 lines
976 B
Lua
44 lines
976 B
Lua
|
|
-- Returns a list of areas that include the provided position
|
|
function areas:getAreasAtPos(pos)
|
|
local a = {}
|
|
local px, py, pz = pos.x, pos.y, pos.z
|
|
for id, area in pairs(self.areas) do
|
|
local ap1, ap2 = area.pos1, area.pos2
|
|
if px >= ap1.x and px <= ap2.x and
|
|
py >= ap1.y and py <= ap2.y and
|
|
pz >= ap1.z and pz <= ap2.z then
|
|
a[id] = area
|
|
end
|
|
end
|
|
return a
|
|
end
|
|
|
|
-- Checks if the area is unprotected or owned by you
|
|
function areas:canInteract(pos, name)
|
|
if minetest.check_player_privs(name, {areas=true}) then
|
|
return true
|
|
end
|
|
local owned = false
|
|
for _, area in pairs(self:getAreasAtPos(pos)) do
|
|
if area.owner == name then
|
|
return true
|
|
else
|
|
if not area.open then
|
|
owned = true
|
|
end
|
|
end
|
|
end
|
|
return not owned
|
|
end
|
|
|
|
-- Returns a table (list) of all players that own an area
|
|
function areas:getNodeOwners(pos)
|
|
local owners = {}
|
|
for _, area in pairs(self:getAreasAtPos(pos)) do
|
|
table.insert(owners, area.owner)
|
|
end
|
|
return owners
|
|
end
|
|
|