From 65013863b2ae1205f08000c83bdc3b6c8fab5627 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sat, 12 Jul 2014 19:06:05 -0400 Subject: [PATCH] Make canInteractInArea player optional and add an admin check --- api.lua | 23 +++++++++++++++-------- init.lua | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/api.lua b/api.lua index bdb886a..7b10a87 100644 --- a/api.lua +++ b/api.lua @@ -16,7 +16,7 @@ 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 + if minetest.check_player_privs(name, self.adminPrivs) then return true end local owned = false @@ -43,26 +43,33 @@ end -- 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 -- 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 Un-owned intersecting area id, if found. function areas:canInteractInArea(pos1, pos2, name) + if name and minetest.check_player_privs(name, self.adminPrivs) then + return true + end areas:sortPos(pos1, pos2) -- First check for a fully enclosing owned area - for id, area in pairs(self.areas) do - -- A little optimization: isAreaOwner isn't necessary here - -- since we're iterating through all areas. - if area.owner == name and self:isSubarea(pos1, pos2, id) then - return true + if name then + for id, area in pairs(self.areas) do + -- A little optimization: isAreaOwner isn't necessary + -- here since we're iterating through all areas. + if area.owner == name and + self:isSubarea(pos1, pos2, id) then + return true + 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 local p1, p2 = area.pos1, area.pos2 if (p1.x <= pos2.x and p2.x >= pos1.x) and (p1.y <= pos2.y and p2.y >= pos1.y) and (p1.z <= pos2.z and p2.z >= pos1.z) then -- Found an intersecting area - if not areas:isAreaOwner(id, name) then + if not name or not areas:isAreaOwner(id, name) then return false, id end end diff --git a/init.lua b/init.lua index 25ce98b..1e85a5a 100644 --- a/init.lua +++ b/init.lua @@ -4,6 +4,7 @@ areas = {} +areas.adminPrivs = {areas=true} areas.startTime = os.clock() areas.modpath = minetest.get_modpath("areas")