@@ -252,6 +252,16 @@ function areas:getChildren(id)
252252 return children
253253end
254254
255+ function areas :getAreasCount (name )
256+ local count = 0
257+ for _ , area in pairs (self .areas ) do
258+ if area .owner == name then
259+ count = count + 1
260+ end
261+ end
262+ return count
263+ end
264+
255265-- Checks if the user has sufficient privileges.
256266-- If the player is not a administrator it also checks
257267-- if the area intersects other areas that they do not own.
260270function areas :canPlayerAddArea (pos1 , pos2 , name )
261271 local privs = minetest .get_player_privs (name )
262272 if privs .areas then
273+ if areas :getAreasCount (name ) >= self .config .self_max_areas_per_player then
274+ return false , S (" You have reached the limit of areas." )
275+ end
276+
263277 return true
264278 end
265279
@@ -282,16 +296,10 @@ function areas:canPlayerAddArea(pos1, pos2, name)
282296 end
283297
284298 -- Check number of areas the user has and make sure it not above the max
285- local count = 0
286- for _ , area in pairs (self .areas ) do
287- if area .owner == name then
288- count = count + 1
289- end
290- end
291299 local max_areas = privs .areas_high_limit and
292300 self .config .self_protection_max_areas_high or
293301 self .config .self_protection_max_areas
294- if count >= max_areas then
302+ if areas : getAreasCount ( name ) >= max_areas then
295303 return false , S (" You have reached the maximum amount of"
296304 .. " areas that you are allowed to protect." )
297305 end
310318function areas :canPlayerAddOwner (pos1 , pos2 , name )
311319 local privs = minetest .get_player_privs (name )
312320 if privs .areas then
321+ if areas :getAreasCount (name ) >= self .config .self_max_areas_per_player then
322+ return false , S (" You have reached the limit of areas." )
323+ end
324+
313325 return true
314326 end
315327
@@ -324,16 +336,10 @@ function areas:canPlayerAddOwner(pos1, pos2, name)
324336 end
325337
326338 -- Check number of areas the user has and make sure it not above the max
327- local count = 0
328- for _ , area in pairs (self .areas ) do
329- if area .owner == name then
330- count = count + 1
331- end
332- end
333339 local max_areas = privs .areas_high_limit and
334340 self .config .self_protection_max_areas_high or
335341 self .config .self_protection_max_areas
336- if count >= max_areas then
342+ if areas : getAreasCount ( name ) >= max_areas then
337343 return false , S (" Target player has reached the maximum amount of"
338344 .. " areas they are allowed to protect." )
339345 end
0 commit comments