mirror of
https://github.com/minetest-mods/areas.git
synced 2024-12-22 21:02:22 +01:00
Make canInteractInArea player optional and add an admin check
This commit is contained in:
parent
e17cda925b
commit
65013863b2
23
api.lua
23
api.lua
@ -16,7 +16,7 @@ end
|
|||||||
|
|
||||||
-- Checks if the area is unprotected or owned by you
|
-- Checks if the area is unprotected or owned by you
|
||||||
function areas:canInteract(pos, name)
|
function areas:canInteract(pos, name)
|
||||||
if minetest.check_player_privs(name, {areas=true}) then
|
if minetest.check_player_privs(name, self.adminPrivs) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local owned = false
|
local owned = false
|
||||||
@ -43,26 +43,33 @@ end
|
|||||||
-- Note that this fails and returns false when the specified area is fully
|
-- Note that this fails and returns false when the specified area is fully
|
||||||
-- owned by the player, but with miltiple protection zones, none of which
|
-- owned by the player, but with miltiple protection zones, none of which
|
||||||
-- cover the entire checked area.
|
-- cover the entire checked area.
|
||||||
|
-- @param name (optional) player name. If not specified checks for any intersecting areas.
|
||||||
-- @return Boolean indicating whether the player can interact in that area.
|
-- @return Boolean indicating whether the player can interact in that area.
|
||||||
-- @return Un-owned intersecting area id, if found.
|
-- @return Un-owned intersecting area id, if found.
|
||||||
function areas:canInteractInArea(pos1, pos2, name)
|
function areas:canInteractInArea(pos1, pos2, name)
|
||||||
|
if name and minetest.check_player_privs(name, self.adminPrivs) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
areas:sortPos(pos1, pos2)
|
areas:sortPos(pos1, pos2)
|
||||||
-- First check for a fully enclosing owned area
|
-- First check for a fully enclosing owned area
|
||||||
for id, area in pairs(self.areas) do
|
if name then
|
||||||
-- A little optimization: isAreaOwner isn't necessary here
|
for id, area in pairs(self.areas) do
|
||||||
-- since we're iterating through all areas.
|
-- A little optimization: isAreaOwner isn't necessary
|
||||||
if area.owner == name and self:isSubarea(pos1, pos2, id) then
|
-- here since we're iterating through all areas.
|
||||||
return true
|
if area.owner == name and
|
||||||
|
self:isSubarea(pos1, pos2, id) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Then check for intersecting non-owned areas
|
-- Then check for intersecting (non-owned) areas
|
||||||
for id, area in pairs(self.areas) do
|
for id, area in pairs(self.areas) do
|
||||||
local p1, p2 = area.pos1, area.pos2
|
local p1, p2 = area.pos1, area.pos2
|
||||||
if (p1.x <= pos2.x and p2.x >= pos1.x) and
|
if (p1.x <= pos2.x and p2.x >= pos1.x) and
|
||||||
(p1.y <= pos2.y and p2.y >= pos1.y) and
|
(p1.y <= pos2.y and p2.y >= pos1.y) and
|
||||||
(p1.z <= pos2.z and p2.z >= pos1.z) then
|
(p1.z <= pos2.z and p2.z >= pos1.z) then
|
||||||
-- Found an intersecting area
|
-- Found an intersecting area
|
||||||
if not areas:isAreaOwner(id, name) then
|
if not name or not areas:isAreaOwner(id, name) then
|
||||||
return false, id
|
return false, id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
1
init.lua
1
init.lua
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
areas = {}
|
areas = {}
|
||||||
|
|
||||||
|
areas.adminPrivs = {areas=true}
|
||||||
areas.startTime = os.clock()
|
areas.startTime = os.clock()
|
||||||
|
|
||||||
areas.modpath = minetest.get_modpath("areas")
|
areas.modpath = minetest.get_modpath("areas")
|
||||||
|
Loading…
Reference in New Issue
Block a user