diff --git a/init.lua b/init.lua index 3886795..1d8c72b 100644 --- a/init.lua +++ b/init.lua @@ -142,6 +142,14 @@ function switch_creative:get_area_size(astore_area) return x*z end +function switch_creative:get_areas_area_size(areas_area) + local pos1 = areas_area.pos1 + local pos2 = areas_area.pos2 + local x = math.abs( pos2.x - pos1.x ) + local z = math.abs( pos2.z - pos1.x ) + return x*z +end + function switch_creative:initial_stuff() local stuff_string = minetest.settings:get("initial_stuff") or "default:pick_steel,default:axe_steel,default:shovel_steel," .. @@ -243,6 +251,7 @@ function switch_creative:update_player(player) local areas_open = false local new_area = nil local smallest_area = {} + local smallest_areas_area = {} if minetest.check_player_privs(name, { protection_bypass=true }) then --minetest.chat_send_player(name, "Changed area. You have protection_bypass priv") @@ -267,6 +276,11 @@ function switch_creative:update_player(player) if minetest.get_modpath("areas") then a_current_areas = areas:getAreasAtPos(pos) for a_id, a_area in pairs( a_current_areas ) do + local areasize = switch_creative:get_areas_area_size(a_area) + if not smallest_areas_area.size or areasize < smallest_areas_area.size then + smallest_areas_area.id = a_id + smallest_areas_area.size = areasize + end player_active_areas = player_active_areas .. ", a"..a_id if a_area.owner == name then areas_owner = true @@ -297,6 +311,11 @@ function switch_creative:update_player(player) end end end + if smallest_areas_area.size and smallest_area.size then + if smallest_area.size <= smallest_areas_area.size then + privstring = privstring .. ", " .. switch_creative.area_privs[smallest_area.id] + end + end end if player_active_areas ~= player_last_active_areas then