Skip to content

Commit

Permalink
Display owner group names on failed interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric Haase committed Dec 17, 2017
1 parent f2653e3 commit c78bf14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 14 additions & 1 deletion api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion interact.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

local old_is_protected = minetest.is_protected
function minetest.is_protected(pos, name)
if not areas:canInteract(pos, name) then
Expand All @@ -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),
Expand Down

0 comments on commit c78bf14

Please sign in to comment.