From aa3e35acbe77983d2c64b8cb24969a5b66df7075 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Sun, 22 Mar 2020 21:26:42 +0100 Subject: [PATCH] /areas_cleanup for removing ownerless areas --- README.md | 3 +++ chatcommands.lua | 25 +++++++++++++++++++++++++ locale/template.txt | 2 ++ 3 files changed, 30 insertions(+) diff --git a/README.md b/README.md index f86494f..e665e52 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,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 ------- diff --git a/chatcommands.lua b/chatcommands.lua index a40403e..9fed5f8 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -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 +}) diff --git a/locale/template.txt b/locale/template.txt index ba62e97..02b9c77 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -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 ###