You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.6 KiB
107 lines
3.6 KiB
-- 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.."/items.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 current_regions_size = {}
|
|
local player_active_region_str = ""
|
|
local areas_owner = false
|
|
local areas_guest = false
|
|
local areas_open = 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 = self.astore:get_areas_for_pos(pos, true, true)
|
|
for astore_id, astore_area in pairs( current_areas ) 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])
|
|
elseif string.sub(region.id, 1, 1) == "r" then
|
|
creative_regions:add_privs_from_string(new_privs_table, default_privs)
|
|
elseif string.sub(region.id, 1, 1) == "a" then
|
|
creative_regions:add_privs_from_string(new_privs_table, areas_guest_privs)
|
|
end
|
|
end
|
|
|
|
-- overwrite
|
|
if areas_owner or areas_open then
|
|
creative_regions:add_privs_from_string(new_privs_table, areas_owner_privs)
|
|
end
|
|
|
|
-- did the regions change? update
|
|
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)
|
|
|