mirror of
https://github.com/minetest-mods/areas.git
synced 2025-07-20 16:40:28 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
87
api.lua
87
api.lua
@ -120,9 +120,9 @@ function areas:getSmallestAreaAtPos(pos)
|
||||
local smallest_area, smallest_id, volume
|
||||
local smallest_volume = math.huge
|
||||
for id, area in pairs(self:getAreasAtPos(pos)) do
|
||||
volume = (area.pos2.x - area.pos1.x + 1)
|
||||
* (area.pos2.y - area.pos1.y + 1)
|
||||
* (area.pos2.z - area.pos1.z + 1)
|
||||
volume = (area.pos2.x - area.pos1.x + 1)
|
||||
* (area.pos2.y - area.pos1.y + 1)
|
||||
* (area.pos2.z - area.pos1.z + 1)
|
||||
if smallest_volume >= volume then
|
||||
smallest_area = area
|
||||
smallest_id = id
|
||||
@ -133,55 +133,60 @@ 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 area.openfarming then
|
||||
-- if area is openfarming
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local node = minetest.get_node(pos).name
|
||||
if player and minetest.registered_nodes[node] then
|
||||
local wstack = player:get_wielded_item():get_name()
|
||||
if wstack == "" then wstack = "hand" end
|
||||
|
||||
--on_dig
|
||||
if minetest.get_item_group(node, "plant") == 1 and (wstack == "hand" or minetest.registered_tools[wstack]) then
|
||||
return true
|
||||
local areas_list
|
||||
if areas.config.use_smallest_area_precedence then
|
||||
local smallest_area, _ = self:getSmallestAreaAtPos(pos)
|
||||
areas_list = { smallest_area }
|
||||
else
|
||||
areas_list = self:getAreasAtPos(pos)
|
||||
end
|
||||
local owned = false
|
||||
for _, area in pairs(areas_list) do
|
||||
-- Player owns the area or area is open
|
||||
if area.owner == name or area.open then
|
||||
return true
|
||||
elseif area.openfarming then -- If area is openfarming
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local node = minetest.get_node(pos).name
|
||||
if player and minetest.registered_nodes[node] then
|
||||
local wstack = player:get_wielded_item():get_name()
|
||||
if wstack == "" then wstack = "hand" end
|
||||
-- on_dig
|
||||
if minetest.get_item_group(node, "plant") == 1
|
||||
and (wstack == "hand" or minetest.registered_tools[wstack]) then
|
||||
return true
|
||||
end
|
||||
-- on_place
|
||||
if plants[wstack] ~= nil and plants[wstack] == node then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
--on_place
|
||||
if plants[wstack] ~= nil and plants[wstack] == node then
|
||||
return true
|
||||
end
|
||||
end
|
||||
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
|
||||
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
|
||||
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
|
||||
owned = true
|
||||
end
|
||||
return false
|
||||
return not owned
|
||||
end
|
||||
|
||||
-- Returns a table (list) of all players that own an area
|
||||
|
Reference in New Issue
Block a user