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.
143 lines
4.9 KiB
143 lines
4.9 KiB
local S = minetest.get_translator("creative_regions")
|
|
|
|
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, true, true)
|
|
if astore_area then
|
|
local success = creative_regions.astore:remove_area(astore_id)
|
|
local edge1 = astore_area.min
|
|
local edge2 = astore_area.max
|
|
local data = tostring(region_name)
|
|
local new_id = nil
|
|
if success then
|
|
new_id = creative_regions.astore:insert_area(edge1, edge2, data, astore_id)
|
|
end
|
|
|
|
if new_id == astore_id then
|
|
minetest.chat_send_player(name, "[creative_regions] Region " .. region_id .. " updated")
|
|
else
|
|
minetest.chat_send_player(name, "[creative_regions] Failed to update region " .. region_id)
|
|
minetest.log("warning", "[creative_regions] Failed to update region " .. region_id)
|
|
end
|
|
else
|
|
minetest.chat_send_player(name, "Failed to update region " .. region_id)
|
|
return false, "Region not found"
|
|
end
|
|
creative_regions.save_regions()
|
|
return true, "Done."
|
|
end,
|
|
})
|
|
|
|
minetest.register_chatcommand("creative_region_clearinv", {
|
|
params = S("<name> <inventory>"),
|
|
description = S("Clear a saved inventory of yourself or another player"),
|
|
privs = {server = true},
|
|
func = function(name, param)
|
|
local player = minetest.get_player_by_name(name)
|
|
local playerName, inventoryListName = param:match("^(%S+)%s(.+)$")
|
|
if not playerName or not inventoryListName then
|
|
return false, "Syntax error"
|
|
end
|
|
|
|
player = minetest.get_player_by_name(playerName)
|
|
if not player then
|
|
return false, S("Player not found")
|
|
end
|
|
|
|
player:get_inventory():set_list(inventoryListName, {})
|
|
minetest.chat_send_player(name, S("Cleared @1's inventory list '@2'", player:get_player_name(), inventoryListName))
|
|
return true, S("Done")
|
|
end,
|
|
})
|
|
|