admin.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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", "protector:protect_hidden"},
  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_area", {
  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", "protector:protect_hidden"})
  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
  98. or minetest.check_player_privs(name, {protection_bypass = true}) then
  99. minetest.add_entity(pos[n], "protector:display")
  100. end
  101. end
  102. end
  103. })
  104. -- ability to hide protection blocks (borrowed from doors mod :)
  105. minetest.register_node("protector:protect_hidden", {
  106. description = "Hidden Protector",
  107. drawtype = "airlike",
  108. paramtype = "light",
  109. paramtype2 = "facedir",
  110. sunlight_propagates = true,
  111. -- has to be walkable for falling nodes to stop falling
  112. walkable = true,
  113. pointable = false,
  114. diggable = false,
  115. buildable_to = false,
  116. floodable = false,
  117. drop = "",
  118. groups = {not_in_creative_inventory = 1, unbreakable = 1},
  119. on_blast = function() end,
  120. -- 1px block inside door hinge near node top
  121. collision_box = {
  122. type = "fixed",
  123. fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32},
  124. },
  125. })
  126. minetest.register_chatcommand("protector_show", {
  127. params = "",
  128. description = S("Show your nearby protection blocks"),
  129. privs = {interact = true},
  130. func = function(name, param)
  131. local player = minetest.get_player_by_name(name)
  132. if not player then
  133. return false, "Player not found"
  134. end
  135. local pos = player:get_pos()
  136. local a = minetest.find_nodes_in_area(
  137. {x = pos.x - r, y = pos.y - r, z = pos.z - r},
  138. {x = pos.x + r, y = pos.y + r, z = pos.z + r},
  139. {"protector:protect_hidden"})
  140. local meta, owner
  141. for _, row in pairs(a) do
  142. meta = minetest.get_meta(row)
  143. owner = meta:get_string("owner") or ""
  144. if owner == name
  145. or minetest.check_player_privs(name, {protection_bypass = true}) then
  146. minetest.swap_node(row, {name = "protector:protect"})
  147. end
  148. end
  149. end
  150. })
  151. minetest.register_chatcommand("protector_hide", {
  152. params = "",
  153. description = S("Hide your nearby protection blocks"),
  154. privs = {interact = true},
  155. func = function(name, param)
  156. local player = minetest.get_player_by_name(name)
  157. if not player then
  158. return false, "Player not found"
  159. end
  160. local pos = player:get_pos()
  161. local a = minetest.find_nodes_in_area(
  162. {x = pos.x - r, y = pos.y - r, z = pos.z - r},
  163. {x = pos.x + r, y = pos.y + r, z = pos.z + r},
  164. {"protector:protect", "protector:protect2"})
  165. local meta, owner
  166. for _, row in pairs(a) do
  167. meta = minetest.get_meta(row)
  168. owner = meta:get_string("owner") or ""
  169. if owner == name
  170. or minetest.check_player_privs(name, {protection_bypass = true}) then
  171. minetest.swap_node(row, {name = "protector:protect_hidden"})
  172. end
  173. end
  174. end
  175. })