|
|
|
if minetest.get_modpath("areas") then
|
|
|
|
|
|
|
|
function creative_regions.protector_set_noflyzone(pos, placer, itemstack, pointed_thing)
|
|
|
|
if not pos or not placer then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local name = placer:get_player_name();
|
|
|
|
local player_owns_id = nil
|
|
|
|
|
|
|
|
local current_areas = areas:getAreasAtPos(pos)
|
|
|
|
for areas_id, areas_area in pairs( current_areas ) do
|
|
|
|
if areas_area.owner == name then
|
|
|
|
player_owns_id = "a"..tostring(areas_id)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if player_owns_id then
|
|
|
|
meta:set_string("infotext", string.format("No-Fly-Zone Protector for area %s owned by %s", player_owns_id, name))
|
|
|
|
meta:set_string("area_id", player_owns_id)
|
|
|
|
meta:set_string("owner", name)
|
|
|
|
|
|
|
|
creative_regions.set_region_privs(tostring(player_owns_id), "-fast, -fly")
|
|
|
|
minetest.chat_send_player(name, "[creative_regions] No-Fly-Zone set for region " .. player_owns_id)
|
|
|
|
creative_regions.save_regions()
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, "[creative_regions] You need to be inside an area to set a No-Fly-Zone")
|
|
|
|
minetest.after(0.2, function(pos)
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end, pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function creative_regions.protector_can_dig(pos, player)
|
|
|
|
if not pos or not player then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local id = meta:get_string("area_id")
|
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
local player_owns_id = nil
|
|
|
|
|
|
|
|
-- allow for players with areas privilege
|
|
|
|
if minetest.check_player_privs(name, { areas=true }) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local current_areas = areas:getAreasAtPos(pos)
|
|
|
|
for areas_id, areas_area in pairs( current_areas ) do
|
|
|
|
if areas_area.owner == name then
|
|
|
|
player_owns_id = "a"..tostring(areas_id)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if player_owns_id then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, "[creative_regions] Cannot remove No-Fly-Zone "..id.." owned by "..owner)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function creative_regions.protector_remove_noflyzone(pos, oldnode, oldmetadata, digger)
|
|
|
|
if not oldmetadata or not oldmetadata.fields then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local owner = oldmetadata.fields.owner
|
|
|
|
local stored_id = oldmetadata.fields.area_id
|
|
|
|
local name = digger:get_player_name()
|
|
|
|
|
|
|
|
local current_areas = areas:getAreasAtPos(pos)
|
|
|
|
for areas_id, areas_area in pairs( current_areas ) do
|
|
|
|
local id = "a"..tostring(areas_id)
|
|
|
|
if stored_id == id then
|
|
|
|
creative_regions.set_region_privs(tostring(id), nil)
|
|
|
|
minetest.chat_send_player(name, "[creative_regions] No-Fly-Zone for area " .. id .. " removed")
|
|
|
|
creative_regions.save_regions()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("creative_regions:protector_nofly", {
|
|
|
|
description = "No-Fly-Zone Protector",
|
|
|
|
tiles = {"creative_regions_protector_nofly.png"},
|
|
|
|
is_ground_content = true,
|
|
|
|
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=1},
|
|
|
|
light_source = 1,
|
|
|
|
after_place_node = creative_regions.protector_set_noflyzone,
|
|
|
|
can_dig = creative_regions.protector_can_dig,
|
|
|
|
after_dig_node = creative_regions.protector_remove_noflyzone,
|
|
|
|
})
|
|
|
|
|
|
|
|
--minetest.register_alias("noflyzone", "creative_regions:noflyprotector")
|
|
|
|
|
|
|
|
end
|