From 3daefe734536d40a21d0dbb1343832948922e696 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Mon, 1 Jun 2020 14:47:02 +0200 Subject: [PATCH] remove protectors on area removal --- mod_areas.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mod_areas.lua b/mod_areas.lua index 1e23c91..c99057b 100644 --- a/mod_areas.lua +++ b/mod_areas.lua @@ -15,8 +15,28 @@ function creative_regions:get_areas_area_size(areas_area) return x*z end --- areas mod hud if minetest.get_modpath("areas") then + +-- remove protector blocks on area removal + areas:registerOnRemove(function(id) + local area = areas.areas[id] + local area_id = "a"..tostring(id) + local protectors_in_area = minetest.find_nodes_in_area(area.pos1, area.pos2, {"creative_regions:"}) + for pos in ipairs(protectors_in_area) do + local meta = minetest.get_meta(pos) + local stored_id = meta:get_string("area_id") + local privstring = meta:get_string("privstring") + local owner = meta:get_string("owner") + creative_regions.set_region_privs(area_id, nil) + creative_regions.save_regions() + if stored_id == area_id and privstring == creative_regions.region_privs[tostring(area_id)] then + minetest.remove_node(pos) + minetest.chat_send_player(owner, "[creative_regions] "..description.." removed for removed area " .. area_id) + end + end + end) + +-- areas mod hud local function areas_hud_handler(pos, areas) local current_regions = creative_regions.astore:get_areas_for_pos(pos, false, true) for astore_id, astore_area in pairs( current_regions ) do @@ -31,4 +51,5 @@ if minetest.get_modpath("areas") then end areas:registerHudHandler(areas_hud_handler) + end