Minetest mod: Toggle privs in areas
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.6 KiB

minetest.register_chatcommand("creative_region", {
params = "<x> <y> <z>, <x> <y> <z>, <text>",
description = "Set a creative region from a to b",
privs = {server = true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
local found, _, x1, y1, z1, x2, y2, z2, region_name = param:find("^([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s*,%s*([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s*,%s*(.+)$")
if not found then
return false, "Syntax error"
end
local edge1 = { x=tonumber(x1), y=tonumber(y1), z=tonumber(z1) }
local edge2 = { x=tonumber(x2), y=tonumber(y2), z=tonumber(z2) }
local data = region_name
local astore_id = creative_regions.astore:insert_area(edge1, edge2, tostring(data))
if astore_id then
creative_regions.set_region_privs("r"..tostring(astore_id), nil)
minetest.chat_send_player(name, "[creative_regions] New region set. ID: " .. "r"..astore_id)
creative_regions.save_regions()
return true, "Done"
else
return false, "Failed"
end
end,
})
minetest.register_chatcommand("creative_region_privs", {
params = "<id>, <text>",
description = "Set privstring for creative region",
privs = {server = true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
local found, _, region_id, privstring = param:find("^([ra]%d+)%s*,%s*(.+)$")
if not found or not region_id or not privstring then
return false, "Syntax error"
end
if privstring == "nil" then
privstring = nil
end
creative_regions.set_region_privs(tostring(region_id), privstring)
creative_regions.save_regions()
minetest.chat_send_player(name, "[creative_regions] Privstring set for region " .. region_id .. ": " .. (privstring or "nil"))
return true, "Done"
end,
})
minetest.register_chatcommand("creative_region_rm", {
params = "<id>",
description = "Remove a creative region",
privs = {server = true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
local found, _, region_id = param:find("^(r%d+)%s*$")
if not found or not region_id then
return false, "Syntax error"
end
local astore_id = tonumber(string.sub(region_id, 2))
local success = creative_regions.astore:remove_area(astore_id)
if success then
minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "removed")
creative_regions.set_region_privs(tostring(region_id), nil)
else
minetest.chat_send_player(name, "Failed to remove region " .. region_id)
return false, "Region not found"
end
creative_regions.save_regions()
return true, "Done."
end,
})
minetest.register_chatcommand("creative_region_rn", {
params = "<id>, <text>",
description = "Rename a creative region",
privs = {server = true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "Player not found"
end
local found, _, region_id, region_name = param:find("^(r%d+)%s*,%s*(.+)$")
if not found or not region_id or not region_name then
return false, "Syntax error"
end
local astore_id = tonumber(string.sub(region_id, 2))
local astore_area = creative_regions.astore:get_area(astore_id, false, true)
if astore_area then
astore_area.data = tostring(region_name)
minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. "updated")
creative_regions.save_regions()
else
minetest.chat_send_player(name, "Failed to update region " .. region_id)
return false, "Region not found"
end
return true, "Done."
end,
})