Display owner group names on failed interaction
This commit is contained in:
parent
f2653e3748
commit
c78bf1428f
15
api.lua
15
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
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue