remove builtin protection and register them with areas:registerProtectionCondition
This commit is contained in:
parent
b8e7567a9c
commit
d72735c5fa
110
internal.lua
110
internal.lua
|
@ -206,60 +206,10 @@ function areas:getChildren(id)
|
||||||
return children
|
return children
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Checks if the user has sufficient privileges.
|
|
||||||
-- If the player is not a administrator it also checks
|
|
||||||
-- if the area intersects other areas that they do not own.
|
|
||||||
-- Also checks the size of the area and if the user already
|
|
||||||
-- has more than max_areas.
|
|
||||||
-- checks all possible restrictions registered with
|
-- checks all possible restrictions registered with
|
||||||
-- areas:registerProtectionCondition
|
-- areas:registerProtectionCondition
|
||||||
|
-- builtin callbacks below
|
||||||
function areas:canPlayerAddArea(pos1, pos2, name)
|
function areas:canPlayerAddArea(pos1, pos2, name)
|
||||||
local privs = minetest.get_player_privs(name)
|
|
||||||
if privs.areas then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check self protection privilege, if it is enabled,
|
|
||||||
-- and if the area is too big.
|
|
||||||
if not self.config.self_protection or
|
|
||||||
not privs[areas.config.self_protection_privilege] then
|
|
||||||
return false, S("Self protection is disabled or you do not have"
|
|
||||||
.." the necessary privilege.")
|
|
||||||
end
|
|
||||||
|
|
||||||
local max_size = privs.areas_high_limit and
|
|
||||||
self.config.self_protection_max_size_high or
|
|
||||||
self.config.self_protection_max_size
|
|
||||||
if
|
|
||||||
(pos2.x - pos1.x + 1) > max_size.x or
|
|
||||||
(pos2.y - pos1.y + 1) > max_size.y or
|
|
||||||
(pos2.z - pos1.z + 1) > max_size.z then
|
|
||||||
return false, S("Area is too big.")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check number of areas the user has and make sure it not above the max
|
|
||||||
local count = 0
|
|
||||||
for _, area in pairs(self.areas) do
|
|
||||||
if area.owner == name then
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local max_areas = privs.areas_high_limit and
|
|
||||||
self.config.self_protection_max_areas_high or
|
|
||||||
self.config.self_protection_max_areas
|
|
||||||
if count >= max_areas then
|
|
||||||
return false, S("You have reached the maximum amount of"
|
|
||||||
.." areas that you are allowed to protect.")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check intersecting areas
|
|
||||||
local can, id = self:canInteractInArea(pos1, pos2, name)
|
|
||||||
if not can then
|
|
||||||
local area = self.areas[id]
|
|
||||||
return false, S("The area intersects with @1 [@2] (@3).",
|
|
||||||
area.name, id, area.owner)
|
|
||||||
end
|
|
||||||
|
|
||||||
local allowed = true
|
local allowed = true
|
||||||
local errMsg
|
local errMsg
|
||||||
for i=1, #areas.registered_protection_conditions do
|
for i=1, #areas.registered_protection_conditions do
|
||||||
|
@ -278,6 +228,64 @@ function areas:canPlayerAddArea(pos1, pos2, name)
|
||||||
return allowed, errMsg
|
return allowed, errMsg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Checks if the user has sufficient privileges.
|
||||||
|
areas:registerProtectionCondition(function(pos1, pos2, name)
|
||||||
|
local privs = minetest.get_player_privs(name)
|
||||||
|
if privs.areas then
|
||||||
|
-- always allow administrators to create areas
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check self protection privilege
|
||||||
|
if not areas.config.self_protection or
|
||||||
|
not privs[areas.config.self_protection_privilege] then
|
||||||
|
return false, S("Self protection is disabled or you do not have"
|
||||||
|
.." the necessary privilege.")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- check if the area is too big
|
||||||
|
areas:registerProtectionCondition(function(pos1, pos2, name)
|
||||||
|
local privs = minetest.get_player_privs(name)
|
||||||
|
local max_size = privs.areas_high_limit and
|
||||||
|
areas.config.self_protection_max_size_high or
|
||||||
|
areas.config.self_protection_max_size
|
||||||
|
if
|
||||||
|
(pos2.x - pos1.x + 1) > max_size.x or
|
||||||
|
(pos2.y - pos1.y + 1) > max_size.y or
|
||||||
|
(pos2.z - pos1.z + 1) > max_size.z then
|
||||||
|
return false, S("Area is too big.")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Check number of areas the user has and make sure it not above the max
|
||||||
|
areas:registerProtectionCondition(function(pos1, pos2, name)
|
||||||
|
local privs = minetest.get_player_privs(name)
|
||||||
|
local count = 0
|
||||||
|
for _, area in pairs(areas.areas) do
|
||||||
|
if area.owner == name then
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local max_areas = privs.areas_high_limit and
|
||||||
|
areas.config.self_protection_max_areas_high or
|
||||||
|
areas.config.self_protection_max_areas
|
||||||
|
if count >= max_areas then
|
||||||
|
return false, S("You have reached the maximum amount of"
|
||||||
|
.." areas that you are allowed to protect.")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- checks if the area intersects other areas that the player do not own.
|
||||||
|
areas:registerProtectionCondition(function(pos1, pos2, name)
|
||||||
|
local can, id = areas:canInteractInArea(pos1, pos2, name)
|
||||||
|
if not can then
|
||||||
|
local area = areas.areas[id]
|
||||||
|
return false, S("The area intersects with @1 [@2] (@3).",
|
||||||
|
area.name, id, area.owner)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Given a id returns a string in the format:
|
-- Given a id returns a string in the format:
|
||||||
-- "name [id]: owner (x1, y1, z1) (x2, y2, z2) -> children"
|
-- "name [id]: owner (x1, y1, z1) (x2, y2, z2) -> children"
|
||||||
function areas:toString(id)
|
function areas:toString(id)
|
||||||
|
|
Loading…
Reference in New Issue