Minetest mod: Toggle privs in areas
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.

123 lines
3.9 KiB

-- creative_regions mod by h3ndrik
5 years ago
creative_regions = {}
5 years ago
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"
5 years ago
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"
5 years ago
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")
5 years ago
dofile(creative_regions.modpath.."/items.lua")
dofile(creative_regions.modpath.."/mod_areas.lua")
5 years ago
function creative_regions:update_player(player)
5 years ago
local name = player:get_player_name()
local pos = vector.round(player:get_pos())
local pmeta = player:get_meta()
5 years ago
-- 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"
5 years ago
local areas_owner = false
local areas_guest = false
local areas_open = false
5 years ago
local smallest_region = {}
local smallest_areas_area = {}
5 years ago
if minetest.check_player_privs(name, { protection_bypass=true }) then
5 years ago
--minetest.chat_send_player(name, "Changed region. You have protection_bypass priv")
5 years ago
return
end
5 years ago
-- enter region
local current_regions = self.astore:get_areas_for_pos(pos, true, true)
5 years ago
for astore_id, astore_area in pairs( current_areas ) do
5 years ago
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
5 years ago
end
end
5 years ago
if smallest_region.id then
player_active_regions = tostring(smallest_region.id)
5 years ago
end
5 years ago
-- 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
5 years ago
smallest_areas_area.id = tostring(a_id)
smallest_areas_area.size = areasize
end
5 years ago
player_active_areas = player_active_areas .. ", a"..a_id
5 years ago
if a_area.owner == name then
areas_owner = true
break
elseif a_area.open then
areas_open = true
break
5 years ago
else
areas_guest = true
5 years ago
--continue
5 years ago
end
end
end
5 years ago
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
5 years ago
end
if areas_owner or areas_open then
5 years ago
privstring = privstring .. ", " .. areas_owner_privs
elseif areas_guest then
5 years ago
privstring = privstring .. ", " .. areas_guest_privs
5 years ago
for _, a in pairs(string.split(player_active_regions, ",")) do
5 years ago
a = a:trim()
if string.sub(a, 1, 1) == "a" then
5 years ago
if creative_regions.region_privs[a] then
privstring = privstring .. ", " .. creative_regions.region_privs[a]
5 years ago
end
end
5 years ago
end
5 years ago
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
5 years ago
end
5 years ago
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)
5 years ago
end
-- print(dump(pmeta:to_table()))
end
5 years ago
creative_regions:load_regions()
5 years ago
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)
5 years ago
end
end
end)