is_area_protected.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local has_areas_mod = minetest.get_modpath("areas")
  2. local has_protector_mod = minetest.get_modpath("protector")
  3. local protector_radius = (tonumber(minetest.settings:get("protector_radius")) or 5)
  4. jumpdrive.is_area_protected = function(pos1, pos2, playername)
  5. local radius_vector = {x=protector_radius, y=protector_radius, z=protector_radius}
  6. local check_pos1 = vector.subtract(pos1, radius_vector)
  7. local check_pos2 = vector.add(pos2, radius_vector)
  8. -- preload area with voxel manip
  9. minetest.get_voxel_manip(check_pos1, check_pos2)
  10. if minetest.is_area_protected then
  11. -- use area protection check
  12. if minetest.is_area_protected(pos1, pos2, playername, 8) then
  13. return true
  14. end
  15. elseif has_protector_mod then
  16. -- use improvised find_nodes check
  17. local protectors = minetest.find_nodes_in_area(
  18. check_pos1, check_pos2, {
  19. "protector:protect",
  20. "protector:protect2",
  21. "priv_protector:protector",
  22. "xp_redo:protector"
  23. }
  24. )
  25. if protectors then
  26. for _,pos in pairs(protectors) do
  27. if minetest.is_protected(pos, playername) then
  28. return true
  29. end
  30. end
  31. end
  32. end
  33. if has_areas_mod then
  34. if not areas:canInteractInArea(pos1, pos2, playername, true) then
  35. -- player can't interact
  36. return true
  37. end
  38. end
  39. -- no protection
  40. return false
  41. end