/areas_cleanup for removing ownerless areas

This commit is contained in:
MoNTE48 2020-03-22 21:26:42 +01:00 committed by SmallJoker
parent 800a93f5ee
commit aa3e35acbe
3 changed files with 30 additions and 0 deletions

View File

@ -102,6 +102,9 @@ Commands
* `/area_pos2 [X,Y,Z|X Y Z]` -- Sets area position two to your position or
the one supplied.
* `/areas_cleanup` -- Removes all ownerless areas.
Useful for cleaning after user deletion, for example using /remove_player.
License
-------

View File

@ -417,3 +417,28 @@ minetest.register_chatcommand("area_info", {
return true, table.concat(lines, "\n")
end,
})
minetest.register_chatcommand("areas_cleanup", {
description = S("Removes all ownerless areas"),
privs = areas.adminPrivs,
func = function()
local total, count = 0, 0
local aareas = areas.areas
for id, _ in pairs(aareas) do
local owner = aareas[id].owner
if not areas:player_exists(owner) then
areas:remove(id)
count = count + 1
end
total = total + 1
end
areas:save()
return true, "Total areas: " .. total .. ", Removed " ..
count .. " areas. New count: " .. (total - count)
end
})

View File

@ -65,6 +65,8 @@ You have extended area protection limits ("areas_high_limit" privilege).=
You have the necessary privilege ("@1").=
You need to select an area first.=
Removes all ownerless areas.=
### chatcommands.lua ###
### pos.lua ###