From c78bf1428ff4e63b165edb04d07317b7181dadd2 Mon Sep 17 00:00:00 2001 From: Cedric Haase Date: Sun, 17 Dec 2017 21:16:00 +0100 Subject: [PATCH] Display owner group names on failed interaction --- api.lua | 15 ++++++++++++++- interact.lua | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/api.lua b/api.lua index 5f3e73e..b5cfe3e 100644 --- a/api.lua +++ b/api.lua @@ -87,11 +87,24 @@ end function areas:getNodeOwners(pos) local owners = {} for _, area in pairs(self:getAreasAtPos(pos)) do - table.insert(owners, area.owner) + if area.owner and (area.owner ~= "") then + table.insert(owners, area.owner) + end end return owners end +-- Returns a table (list) of all groups that own an area +function areas:getNodeOwnerGroups(pos) + local ownerGroups = {} + for _, area in pairs(self:getAreasAtPos(pos)) do + if area.group then + table.insert(ownerGroups, area.group) + end + end + return ownerGroups +end + --- Checks if the area intersects with an area that the player can't interact in. -- Note that this fails and returns false when the specified area is fully -- owned by the player, but with multiple protection zones, none of which diff --git a/interact.lua b/interact.lua index 2e54800..9da2ab7 100644 --- a/interact.lua +++ b/interact.lua @@ -1,4 +1,3 @@ - local old_is_protected = minetest.is_protected function minetest.is_protected(pos, name) if not areas:canInteract(pos, name) then @@ -10,6 +9,11 @@ end minetest.register_on_protection_violation(function(pos, name) if not areas:canInteract(pos, name) then local owners = areas:getNodeOwners(pos) + + if not owners[1] then + owners = areas:getNodeOwnerGroups(pos) + end + minetest.chat_send_player(name, ("%s is protected by %s."):format( minetest.pos_to_string(pos),