admin.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. local S = protector.intllib
  2. local removal_names = ""
  3. local replace_names = ""
  4. minetest.register_chatcommand("protector_remove", {
  5. params = S("<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. S("Protector Names to remove: @1",
  12. removal_names))
  13. return
  14. end
  15. if param == "-" then
  16. minetest.chat_send_player(name,
  17. S("Name List Reset"))
  18. removal_names = ""
  19. return
  20. end
  21. removal_names = param
  22. end,
  23. })
  24. minetest.register_chatcommand("protector_replace", {
  25. params = S("<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. replace_names = ""
  33. return
  34. end
  35. -- show name info
  36. if param == ""
  37. and replace_names ~= "" then
  38. local names = replace_names:split(" ")
  39. minetest.chat_send_player(name,
  40. S("Replacing Protector name @1 with @2",
  41. names[1] or "", names[2] or ""))
  42. return
  43. end
  44. 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 removal_names == ""
  54. and replace_names == "" then
  55. return
  56. end
  57. local meta = minetest.get_meta(pos)
  58. if not meta then return end
  59. local owner = meta:get_string("owner")
  60. if removal_names ~= "" then
  61. local names = 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 replace_names ~= "" then
  69. local names = 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", S("Protection (owned by @1)", names[2]))
  73. end
  74. end
  75. end
  76. })
  77. -- get protection radius
  78. local r = tonumber(minetest.settings:get("protector_radius")) or 5
  79. -- show protection areas of nearby protectors owned by you (thanks agaran)
  80. minetest.register_chatcommand("protector_show", {
  81. params = "",
  82. description = S("Show protected areas of your nearby protectors"),
  83. privs = {},
  84. func = function(name, param)
  85. local player = minetest.get_player_by_name(name)
  86. local pos = player:get_pos()
  87. -- find the protector nodes
  88. local pos = minetest.find_nodes_in_area(
  89. {x = pos.x - r, y = pos.y - r, z = pos.z - r},
  90. {x = pos.x + r, y = pos.y + r, z = pos.z + r},
  91. {"protector:protect", "protector:protect2"})
  92. local meta, owner
  93. -- show a maximum of 5 protected areas only
  94. for n = 1, math.min(#pos, 5) do
  95. meta = minetest.get_meta(pos[n])
  96. owner = meta:get_string("owner") or ""
  97. if owner == name then
  98. minetest.add_entity(pos[n], "protector:display")
  99. end
  100. end
  101. end
  102. })