Skip to content

Commit

Permalink
make smallest area concept optional
Browse files Browse the repository at this point in the history
  • Loading branch information
SwissalpS committed Sep 17, 2024
1 parent 2d15113 commit 68e8237
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
64 changes: 46 additions & 18 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,65 @@ function areas:getSmallestAreaAtPos(pos)
end

-- 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)
if minetest.check_player_privs(name, self.adminPrivs) then
return true
end
local area = self:getSmallestAreaAtPos(pos)
-- No area, player owns it or area is open
if not area
or area.owner == name
or area.open
then
return true
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
if areas.config.use_smallest_area_precedence then
local area = self:getSmallestAreaAtPos(pos)
-- No area, player owns it or area is open
if not area
or area.owner == name
or area.open
then
return true
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 or {}) do
if faction_name == fname then
return true
end
end
end
else
for _, fname in ipairs(area.faction_open or {}) do
if faction_name == fname then
if factions.player_is_in_faction(fname, name) then
return true
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
return false
else
local owned = false
for _, area in pairs(self:getAreasAtPos(pos)) do
if area.owner == name or area.open then
return true
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 or {}) do
if faction_name == fname then
return true
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
return not owned
end
return false
end

-- Returns a table (list) of all players that own an area
Expand Down
3 changes: 3 additions & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Static paths do not work well with settings
#areas.filename (Configuration file path) string (world_path)/areas.dat

# Use smallest area volume precedence concept. (experimental may change)
areas.use_smallest_area_precedence (Smallest area rules) bool false

# Allow players with a privilege create their own areas using /protect
# within the specified size and amount limits.
areas.self_protection (Self protection) bool false
Expand Down

0 comments on commit 68e8237

Please sign in to comment.