protector/admin.lua

120 lines
2.3 KiB
Lua
Raw Normal View History

2016-06-07 21:29:06 +02:00
local S = protector.intllib
protector.removal_names = ""
protector.replace_names = ""
minetest.register_chatcommand("protector_remove", {
params = "<names list>",
description = S("Remove Protectors around players (separate names with spaces)"),
privs = {server = true},
func = function(name, param)
if not param or param == "" then
minetest.chat_send_player(name,
"Protector Names to remove: "
.. protector.removal_names)
return
end
if param == "-" then
minetest.chat_send_player(name,
2016-06-07 21:29:06 +02:00
S("Name List Reset"))
protector.removal_names = ""
return
end
protector.removal_names = param
end,
})
minetest.register_chatcommand("protector_replace", {
params = "<owner name> <name to replace with>",
description = S("Replace Protector Owner with name provided"),
privs = {server = true},
func = function(name, param)
if not param or param == "" then
if protector.replace_names ~= "" then
local names = protector.replace_names:split(" ")
minetest.chat_send_player(name,
"Replacing Protector name '" .. names[1]
.. "' with '" .. names[2] .. "'")
return
else
minetest.chat_send_player(name,
"Usage: /protector_replace <owner name> <new owner name>")
return
end
end
if param == "-" then
minetest.chat_send_player(name,
S("Name List Reset"))
protector.replace_names = ""
return
end
protector.replace_names = param
end,
})
minetest.register_abm({
nodenames = {"protector:protect", "protector:protect2"},
interval = 8,
chance = 1,
catch_up = false,
action = function(pos, node)
if protector.removal_names == ""
2017-01-08 18:12:23 +01:00
and protector.replace_names == "" then
return
end
local meta = minetest.get_meta(pos) ; if not meta then return end
local owner = meta:get_string("owner")
--local members = meta:get_string("members")
if protector.removal_names ~= "" then
local names = protector.removal_names:split(" ")
for _, n in pairs(names) do
if n == owner then
minetest.set_node(pos, {name = "air"})
end
end
end
if protector.replace_names ~= "" then
local names = protector.replace_names:split(" ")
if owner == names[1] then
meta:set_string("owner", names[2])
meta:set_string("infotext", "Protection (owned by " .. names[2] .. ")")
end
end
end
2016-06-05 13:06:59 +02:00
})