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.

75 lines
2.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(tostring(astore_id), nil)
minetest.chat_send_player(name, "[creative_regions] New region set. ID: " .. 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("^([+-]?%a?%d+)%s*,%s*(.+)$")
if not found or not region_id or not privstring then
return false, "Syntax error"
end
creative_regions:set_region_privs(tostring(region_id), privstring)
minetest.chat_send_player(name, "[creative_regions] Privstring set for region " .. region_id .. ": " .. privstring)
creative_regions:save_regions()
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("^([+-]?%d+)%s*$")
if not found or not region_id then
return false, "Syntax error"
end
local success = creative_regions.astore:remove_area(tonumber(region_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,
})