-- creative_regions mod by h3ndrik local S = minetest.get_translator("creative_regions") 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 "" 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" non_sticky_privs = {"arena"} -- always remove areas priv when not explicitly requested by current area 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.."/items.lua") dofile(creative_regions.modpath.."/mod_areas.lua") dofile(creative_regions.modpath.."/arena.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 current_regions_size = {} local player_active_region_str = "" local areas_owner = false local areas_guest = false local areas_open = false local areas_individual_override = false -- skip for players with protection_bypass if minetest.check_player_privs(name, { protection_bypass=true }) then return end -- find active regions local current_regions = creative_regions.astore:get_areas_for_pos(pos, true, true) for astore_id, astore_area in pairs( current_regions ) do local id = "r"..tostring(astore_id) local size = creative_regions:get_region_size(astore_area) table.insert(current_regions_size, { ["id"]=id, ["size"]=size }) end -- find active areas from areas mod if minetest.get_modpath("areas") then local current_areas = areas:getAreasAtPos(pos) for areas_id, areas_area in pairs( current_areas ) do local id = "a"..tostring(areas_id) local size = creative_regions:get_areas_area_size(areas_area) table.insert(current_regions_size, { ["id"]=id, ["size"]=size }) if areas_area.owner == name then areas_owner = true elseif areas_area.open then areas_open = true else areas_guest = true --continue end end end -- calculate privs starting with biggest region and overwriting conscutively local new_privs_table = {} creative_regions:add_privs_from_string(new_privs_table, noregion_privs) table.sort(current_regions_size, function(a,b) return a["size"] > b["size"] end) for _, region in ipairs(current_regions_size) do player_active_region_str = player_active_region_str .. "," .. region.id if creative_regions.region_privs[region.id] then creative_regions:add_privs_from_string(new_privs_table, creative_regions.region_privs[region.id]) if string.sub(region.id, 1, 1) == "a" then areas_individual_override = true end elseif string.sub(region.id, 1, 1) == "r" then -- region creative_regions:add_privs_from_string(new_privs_table, default_privs) elseif string.sub(region.id, 1, 1) == "a" then -- areas mod if not areas_individual_override then creative_regions:add_privs_from_string(new_privs_table, areas_guest_privs) end end end -- overwrite if areas_owner or areas_open then creative_regions:add_privs_from_string(new_privs_table, areas_owner_privs) creative_regions:add_privs_from_string(new_privs_table, "-arena") end -- did the regions change? update -- ToDo: Update on privileges changed local player_last_active_region_str = pmeta:get_string("creative_regions.active_regions") or "" if player_active_region_str ~= player_last_active_region_str then creative_regions:player_enter_region(player, new_privs_table) pmeta:set_string("creative_regions.active_regions", player_active_region_str) 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)