Skip to content

Commit e789ff5

Browse files
committed
Add hard limit even for admin
1 parent 215719e commit e789ff5

34 files changed

Lines changed: 53 additions & 14 deletions

internal.lua

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@ function areas:getChildren(id)
252252
return children
253253
end
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.
@@ -260,6 +270,10 @@ end
260270
function 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
@@ -310,6 +318,10 @@ end
310318
function 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

locale/areas.ar.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=يمكن إدارة المناطق
33
Can protect more, bigger areas=يمكن حماية مناطق أكبر وأكثر
44
Can protect areas=يمكن حماية المناطق
5+
You have reached the limit of areas.=لقد وصلت إلى الحد الأقصى لعدد المناطق.
56

67
### chatcommands.lua ###
78

locale/areas.bg.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=Може да администрира области
33
Can protect more, bigger areas=Може да защитава повече и по-големи площи
44
Can protect areas=Може да защитава области
5+
You have reached the limit of areas.=Достигнахте максималния брой зони.
56

67
### chatcommands.lua ###
78

locale/areas.cs.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=Může spravovat oblasti
33
Can protect more, bigger areas=Může chránit více větších oblastí
44
Can protect areas=Může chránit oblasti
5+
You have reached the limit of areas.=Dosáhli jste limitu oblastí.
56

67
### chatcommands.lua ###
78

locale/areas.da.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=Kan administrere områder
33
Can protect more, bigger areas=Kan beskytte flere og større områder
44
Can protect areas=Kan beskytte områder
5+
You have reached the limit of areas.=Du har nået grænsen for områder.
56

67
### chatcommands.lua ###
78

locale/areas.de.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=Kann Bereiche verwalten
33
Can protect more, bigger areas=Kann mehr und größere Bereiche schützen
44
Can protect areas=Kann Bereiche schützen
5+
You have reached the limit of areas.=Du hast die maximale Anzahl an Bereichen erreicht.
56

67
### chatcommands.lua ###
78

locale/areas.el.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=Μπορεί να διαχειριστεί περιοχές
33
Can protect more, bigger areas=Μπορεί να προστατεύσει περισσότερες, μεγαλύτερες περιοχές
44
Can protect areas=Μπορεί να προστατεύσει περιοχές
5+
You have reached the limit of areas.=Έχετε φτάσει το όριο περιοχών.
56

67
### chatcommands.lua ###
78

locale/areas.es.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=Puede administrar zonas
33
Can protect more, bigger areas=Puede proteger más zonas y de mayor tamaño
44
Can protect areas=Puede proteger zonas
5+
You have reached the limit of areas.=Alcanzaste el límite de áreas.
56

67
### chatcommands.lua ###
78

locale/areas.et.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=Saab hallata valdkondi
33
Can protect more, bigger areas=Saab kaitsta rohkem ja suuremaid alasid
44
Can protect areas=Võib kaitsta alasid
5+
You have reached the limit of areas.=Oled jõudnud alade limiidini.
56

67
### chatcommands.lua ###
78

locale/areas.fi.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Can administer areas=Voi hallinnoida alueita
33
Can protect more, bigger areas=Voidaan suojata useampia ja suurempia alueita
44
Can protect areas=Voi suojella alueita
5+
You have reached the limit of areas.=Olet saavuttanut alueiden enimmäismäärän.
56

67
### chatcommands.lua ###
78

0 commit comments

Comments
 (0)