admin.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. local S = protector.intllib
  2. protector.removal_names = ""
  3. protector.replace_names = ""
  4. minetest.register_chatcommand("protector_remove", {
  5. params = "<names list>",
  6. description = S("Remove Protectors around players (separate names with spaces)"),
  7. privs = {server = true},
  8. func = function(name, param)
  9. if not param or param == "" then
  10. minetest.chat_send_player(name,
  11. "Protector Names to remove: "
  12. .. protector.removal_names)
  13. return
  14. end
  15. if param == "-" then
  16. minetest.chat_send_player(name,
  17. S("Name List Reset"))
  18. protector.removal_names = ""
  19. return
  20. end
  21. protector.removal_names = param
  22. end,
  23. })
  24. minetest.register_chatcommand("protector_replace", {
  25. params = "<owner name> <name to replace with>",
  26. description = S("Replace Protector Owner with name provided"),
  27. privs = {server = true},
  28. func = function(name, param)
  29. -- reset list to empty
  30. if param == "-" then
  31. minetest.chat_send_player(name, S("Name List Reset"))
  32. protector.replace_names = ""
  33. return
  34. end
  35. -- show name info
  36. if param == ""
  37. and protector.replace_names ~= "" then
  38. local names = protector.replace_names:split(" ")
  39. minetest.chat_send_player(name,
  40. "Replacing Protector name '" .. (names[1] or "")
  41. .. "' with '" .. (names[2] or "").. "'")
  42. return
  43. end
  44. protector.replace_names = param
  45. end,
  46. })
  47. minetest.register_abm({
  48. nodenames = {"protector:protect", "protector:protect2"},
  49. interval = 8,
  50. chance = 1,
  51. catch_up = false,
  52. action = function(pos, node)
  53. if protector.removal_names == ""
  54. and protector.replace_names == "" then
  55. return
  56. end
  57. local meta = minetest.get_meta(pos) ; if not meta then return end
  58. local owner = meta:get_string("owner")
  59. --local members = meta:get_string("members")
  60. if protector.removal_names ~= "" then
  61. local names = protector.removal_names:split(" ")
  62. for _, n in pairs(names) do
  63. if n == owner then
  64. minetest.set_node(pos, {name = "air"})
  65. end
  66. end
  67. end
  68. if protector.replace_names ~= "" then
  69. local names = protector.replace_names:split(" ")
  70. if names[1] and names[2] and owner == names[1] then
  71. meta:set_string("owner", names[2])
  72. meta:set_string("infotext", "Protection (owned by " .. names[2] .. ")")
  73. end
  74. end
  75. end
  76. })
  77. -- show protection areas of nearby protectors owned by you (thanks agaran)
  78. minetest.register_chatcommand("protector_show", {
  79. params = "",
  80. description = "Show protected areas of your nearby protectors",
  81. privs = {},
  82. func = function(name, param)
  83. local player = minetest.get_player_by_name(name)
  84. local pos = player:get_pos()
  85. local r = protector.radius -- max protector range.
  86. -- find the protector nodes
  87. local pos = minetest.find_nodes_in_area(
  88. {x = pos.x - r, y = pos.y - r, z = pos.z - r},
  89. {x = pos.x + r, y = pos.y + r, z = pos.z + r},
  90. {"protector:protect", "protector:protect2"})
  91. local meta, owner
  92. -- show a maximum of 5 protected areas only
  93. for n = 1, math.min(#pos, 5) do
  94. meta = minetest.get_meta(pos[n])
  95. owner = meta:get_string("owner") or ""
  96. if owner == name then
  97. minetest.add_entity(pos[n], "protector:display")
  98. end
  99. end
  100. end
  101. })