Make smallest area concept optional (#80)

This restores the behaviour to before #79.
This commit is contained in:
Luke aka SwissalpS 2024-10-01 17:54:47 +02:00 committed by GitHub
parent 9b6fea1473
commit d2b227eca6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 24 deletions

55
api.lua

@ -101,9 +101,9 @@ function areas:getSmallestAreaAtPos(pos)
local smallest_area, smallest_id, volume local smallest_area, smallest_id, volume
local smallest_volume = math.huge local smallest_volume = math.huge
for id, area in pairs(self:getAreasAtPos(pos)) do for id, area in pairs(self:getAreasAtPos(pos)) do
volume = (area.pos2.x - area.pos1.x + 1) volume = (area.pos2.x - area.pos1.x + 1)
* (area.pos2.y - area.pos1.y + 1) * (area.pos2.y - area.pos1.y + 1)
* (area.pos2.z - area.pos1.z + 1) * (area.pos2.z - area.pos1.z + 1)
if smallest_volume >= volume then if smallest_volume >= volume then
smallest_area = area smallest_area = area
smallest_id = id smallest_id = id
@ -114,37 +114,44 @@ function areas:getSmallestAreaAtPos(pos)
end end
-- Checks if the area is unprotected, open, owned by player -- Checks if the area is unprotected, open, owned by player
-- or player is part of faction of smallest area at position. -- or player is part of faction of [smallest] area at position.
function areas:canInteract(pos, name) function areas:canInteract(pos, name)
if minetest.check_player_privs(name, self.adminPrivs) then if minetest.check_player_privs(name, self.adminPrivs) then
return true return true
end end
local area = self:getSmallestAreaAtPos(pos) local areas_list
-- No area, player owns it or area is open if areas.config.use_smallest_area_precedence then
if not area local smallest_area, _ = self:getSmallestAreaAtPos(pos)
or area.owner == name areas_list = { smallest_area }
or area.open else
then areas_list = self:getAreasAtPos(pos)
return true end
elseif areas.factions_available and area.faction_open then local owned = false
if (factions.version or 0) < 2 then for _, area in pairs(areas_list) do
local faction_name = factions.get_player_faction(name) -- Player owns the area or area is open
if faction_name then if area.owner == name or area.open then
for _, fname in ipairs(area.faction_open or {}) do return true
if faction_name == fname then elseif areas.factions_available and area.faction_open then
if (factions.version or 0) < 2 then
local faction_name = factions.get_player_faction(name)
if faction_name then
for _, fname in ipairs(area.faction_open) do
if faction_name == fname then
return true
end
end
end
else
for _, fname in ipairs(area.faction_open) do
if factions.player_is_in_faction(fname, name) then
return true return true
end end
end end
end end
else
for _, fname in ipairs(area.faction_open or {}) do
if factions.player_is_in_faction(fname, name) then
return true
end
end
end end
owned = true
end end
return false return not owned
end end
-- Returns a table (list) of all players that own an area -- Returns a table (list) of all players that own an area

@ -3,6 +3,20 @@
# Static paths do not work well with settings # Static paths do not work well with settings
#areas.filename (Configuration file path) string (world_path)/areas.dat #areas.filename (Configuration file path) string (world_path)/areas.dat
# Use smallest area volume precedence concept. (experimental; may change)
#
# If set to `true`:
# The interaction permission is defined by the smallest area volume that
# contains the interaction position. Granting access to areas is achieved
# by factions instead of using `/add_owner`.
# This allows players to have private areas within a greater open/shared
# area and also define open/shared areas within those private areas.
# If set to `false`: (default)
# Interacting is permitted if the interaction position resides in any of the
# player's own areas, shared or open areas.
# This permission is not impacted by more restrictive, intersecting areas.
areas.use_smallest_area_precedence (Smallest area rules) bool false
# Allow players with a privilege create their own areas using /protect # Allow players with a privilege create their own areas using /protect
# within the specified size and amount limits. # within the specified size and amount limits.
areas.self_protection (Self protection) bool false areas.self_protection (Self protection) bool false