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.
141 lines
4.8 KiB
141 lines
4.8 KiB
if minetest.get_modpath("areas") then
|
|
|
|
function creative_regions.protector_set_area_privs(pos, placer, itemstack, pointed_thing, privstring, description)
|
|
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
|
|
|
|
-- allow for players with areas privilege
|
|
if not player_owns_id and minetest.check_player_privs(name, { areas=true }) then
|
|
local num_current_areas = 0
|
|
local current_area_id = nil
|
|
for areas_id, areas_area in pairs( current_areas ) do
|
|
num_current_areas = num_current_areas + 1
|
|
current_area_id = "a"..tostring(areas_id)
|
|
end
|
|
if num_current_areas == 1 then
|
|
player_owns_id = current_area_id
|
|
else
|
|
minetest.chat_send_player(name, "[creative_regions] Area ambiguous: You are in multiple areas.")
|
|
minetest.after(0.2, function(pos)
|
|
minetest.remove_node(pos)
|
|
end, pos)
|
|
return
|
|
end
|
|
end
|
|
|
|
if player_owns_id then
|
|
if creative_regions.region_privs[player_owns_id] then
|
|
minetest.chat_send_player(name, "[creative_regions] Failed. Privileges for area already set.")
|
|
minetest.after(0.2, function(pos)
|
|
minetest.remove_node(pos)
|
|
end, pos)
|
|
return
|
|
end
|
|
meta:set_string("infotext", string.format(description.." for area %s owned by %s", player_owns_id, name))
|
|
meta:set_string("area_id", player_owns_id)
|
|
meta:set_string("privstring", privstring)
|
|
meta:set_string("owner", name)
|
|
|
|
creative_regions.set_region_privs(tostring(player_owns_id), privstring)
|
|
minetest.chat_send_player(name, "[creative_regions] "..description.." 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 "..description)
|
|
minetest.after(0.2, function(pos)
|
|
minetest.remove_node(pos)
|
|
end, pos)
|
|
return
|
|
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 privstring = meta:get_string("privstring")
|
|
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
|
|
elseif owner == name then
|
|
return true
|
|
else
|
|
minetest.chat_send_player(name, "[creative_regions] Cannot remove protector block for area "..id.." owned by "..owner)
|
|
return false
|
|
end
|
|
|
|
end
|
|
|
|
function creative_regions.protector_remove_area_privs(pos, oldnode, oldmetadata, digger, description)
|
|
if not oldmetadata or not oldmetadata.fields then
|
|
return
|
|
end
|
|
local owner = oldmetadata.fields.owner
|
|
local stored_id = oldmetadata.fields.area_id
|
|
local privstring = oldmetadata.fields.privstring
|
|
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 and privstring == creative_regions.region_privs[tostring(id)] then
|
|
creative_regions.set_region_privs(id, nil)
|
|
minetest.chat_send_player(name, "[creative_regions] "..description.." removed for area " .. id)
|
|
creative_regions.save_regions()
|
|
else
|
|
minetest.chat_send_player(name, "[creative_regions] Failed to remove privileges!")
|
|
minetest.log("warning", "[creative_regions] Failed to remove privileges for "..description.." at "..dump(pos))
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
minetest.register_node("creative_regions:protector_nofly", {
|
|
description = "No-Fly-Zone protector",
|
|
tiles = {"creative_regions_protector_nofly.png"},
|
|
tiles = {"default_cobble.png^default_clay_brick.png"},
|
|
is_ground_content = true,
|
|
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=1},
|
|
light_source = 1,
|
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
|
return creative_regions.protector_set_area_privs(pos, placer, itemstack, pointed_thing, "-fast, -fly", "No-Fly-Zone Protector")
|
|
end,
|
|
can_dig = creative_regions.protector_can_dig,
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
return creative_regions.protector_remove_area_privs(pos, oldnode, oldmetadata, digger, "No-Fly-Zone protector")
|
|
end
|
|
})
|
|
|
|
--minetest.register_alias("noflyzone", "creative_regions:noflyprotector")
|
|
|
|
end
|
|
|