-- creative_regions mod by h3ndrik creative_regions = {} areas_owner_privs = minetest.settings:get("creative_regions.owner_privs") or "+creative, +fast, +fly" areas_guest_privs = minetest.settings:get("creative_regions.guest_privs") or "-fly, -fast" noregion_privs = minetest.settings:get("creative_regions.noregion_privs") or "-creative, +fast, -fly" default_privs = minetest.settings:get("creative_regions.default_privs") or "+creative, +fast, +fly" creative_regions.modpath = minetest.get_modpath("creative_regions") dofile(creative_regions.modpath.."/region.lua") dofile(creative_regions.modpath.."/player.lua") dofile(creative_regions.modpath.."/chatcommands.lua") dofile(creative_regions.modpath.."/mod_areas.lua") function creative_regions:update_player(player) local name = player:get_player_name() local pos = vector.round(player:get_pos()) local pmeta = player:get_meta() -- pmeta:mark_as_private("creative_regions.active_regions") local player_last_active_regions = pmeta:get_string("creative_regions.active_regions") or "-1" local player_active_regions = "-1" local areas_owner = false local areas_guest = false local areas_open = false local smallest_region = {} local smallest_areas_area = {} if minetest.check_player_privs(name, { protection_bypass=true }) then --minetest.chat_send_player(name, "Changed region. You have protection_bypass priv") return end -- enter region local current_regions = self.astore:get_areas_for_pos(pos, true, true) for astore_id, astore_area in pairs( current_areas ) do local regionsize = creative_regions:get_region_size(astore_area) if not smallest_region.size or regionsize < smallest_region.size then smallest_region.id = tostring(astore_id) smallest_region.size = regionsize end end if smallest_region.id then player_active_regions = tostring(smallest_region.id) end -- enter areas mod area local a_current_areas = {} 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 = creative_regions:get_areas_area_size(a_area) if not smallest_areas_area.size or areasize < smallest_areas_area.size then smallest_areas_area.id = tostring(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 break elseif a_area.open then areas_open = true break else areas_guest = true --continue end end end local privstring = noregion_privs if smallest_region.id then if creative_regions.region_privs[tostring(smallest_region.id)] then privstring = creative_regions.region_privs[tostring(smallest_region.id)] else privstring = default_privs end end if areas_owner or areas_open then privstring = privstring .. ", " .. areas_owner_privs elseif areas_guest then privstring = privstring .. ", " .. areas_guest_privs for _, a in pairs(string.split(player_active_regions, ",")) do a = a:trim() if string.sub(a, 1, 1) == "a" then if creative_regions.region_privs[a] then privstring = privstring .. ", " .. creative_regions.region_privs[a] end end end if smallest_areas_area.size and smallest_region.size then if smallest_region.size <= smallest_areas_area.size then privstring = privstring .. ", " .. creative_regions.region_privs[tostring(smallest_region.id)] end end end if player_active_regions ~= player_last_active_regions then creative_regions:player_enter_region(player, privstring) pmeta:set_string("creative_regions.active_regions", player_active_regions) end -- print(dump(pmeta:to_table())) end creative_regions:load_regions() local timer = 0 minetest.register_globalstep(function(dtime) timer = timer + dtime if timer >= 1 then for _, player in pairs(minetest.get_connected_players()) do creative_regions:update_player(player) end end end)