diff --git a/chatcommands.lua b/chatcommands.lua index 86017cd..ba62ae2 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -67,7 +67,7 @@ minetest.register_chatcommand("creative_region_rm", { local astore_id = tonumber(string.sub(region_id, 2)) local success = creative_regions.astore:remove_area(astore_id) if success then - minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "removed") + minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. " removed") creative_regions.set_region_privs(tostring(region_id), nil) else minetest.chat_send_player(name, "Failed to remove region " .. region_id) @@ -92,16 +92,25 @@ minetest.register_chatcommand("creative_region_rn", { return false, "Syntax error" end local astore_id = tonumber(string.sub(region_id, 2)) - local astore_area = creative_regions.astore:get_area(astore_id, false, true) - if astore_area then - astore_area.data = tostring(region_name) - minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "updated") - creative_regions.save_regions() + local astore_area = creative_regions.astore:get_area(astore_id, true, true) + if astore_area and astore_area.id == astore_id then + local success = creative_regions.astore:remove_area(astore_id) + local edge1 = astore_area.min + local edge2 = astore_area.max + local data = tostring(region_name) + local new_id = creative_regions.astore:insert_area(edge1, edge2, data, astore_id) + + if new_id == astore_id then + minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. " updated") + else + minetest.chat_send_player(name, "[creative_regions] Failed to update region " .. region_id) + minetest.log("warning", "[creative_regions] Failed to update region " .. region_id) + end else minetest.chat_send_player(name, "Failed to update region " .. region_id) return false, "Region not found" end - + creative_regions.save_regions() return true, "Done." end, })