| 
1 | 1 | local S = areas.S  | 
 | 2 | +local posLimit = assert(areas.posLimit)  | 
 | 3 | +areas.posLimit = nil  | 
2 | 4 | 
 
  | 
3 | 5 | minetest.register_chatcommand("protect", {  | 
4 | 6 | 	params = S("<AreaName>"),  | 
@@ -493,3 +495,61 @@ minetest.register_chatcommand("area_pvp", {  | 
493 | 495 | 			not canPvP and S("enabled") or S("disabled"), id)  | 
494 | 496 | 	end  | 
495 | 497 | })  | 
 | 498 | + | 
 | 499 | +local function move_or_resize_area(name, param, resize)  | 
 | 500 | +	local id, dir, amount = param:match("^(%d+)%s([XYZxyz])%s([%-%d]+)$")  | 
 | 501 | +	amount = tonumber(amount)  | 
 | 502 | +	if not amount then  | 
 | 503 | +		return false, S("Invalid usage, see /help @1.", resize and "resize_area" or "move_area")  | 
 | 504 | +	end  | 
 | 505 | + | 
 | 506 | +	id = tonumber(id)  | 
 | 507 | +	if not id then  | 
 | 508 | +		return false, S("That area doesn't exist.")  | 
 | 509 | +	end  | 
 | 510 | + | 
 | 511 | +	local area = areas.areas[id]  | 
 | 512 | +	if not area or not areas:isAreaOwner(id, name) then  | 
 | 513 | +		return false, S("Area @1 does not exist or is not owned by you.", id)  | 
 | 514 | +	end  | 
 | 515 | + | 
 | 516 | +	local delta = {x = 0, y = 0, z = 0}  | 
 | 517 | +	delta[dir:lower()] = amount  | 
 | 518 | +	local pos1, pos2 = vector.sort(area.pos1, area.pos2)  | 
 | 519 | +	if not resize then  | 
 | 520 | +		pos1 = posLimit(vector.add(pos1, delta))  | 
 | 521 | +	end  | 
 | 522 | + | 
 | 523 | +	pos2 = posLimit(vector.add(pos2, delta))  | 
 | 524 | +	local ok, err = areas:canPlayerAddArea(pos1, pos2, name)  | 
 | 525 | +	if not ok then  | 
 | 526 | +		return false, S("You can't move that area there: @1", err)  | 
 | 527 | +	end  | 
 | 528 | + | 
 | 529 | +	if pos2.x < pos1.x or pos2.y < pos1.y or pos2.z < pos1.z then  | 
 | 530 | +		return false, S("You can't make that area that small.")  | 
 | 531 | +	end  | 
 | 532 | + | 
 | 533 | +	areas:move(id, area, pos1, pos2)  | 
 | 534 | + | 
 | 535 | +	-- TODO: Consider only calling areas:save() here once every few seconds  | 
 | 536 | +	areas:save()  | 
 | 537 | + | 
 | 538 | +	return true, resize and S("Area resized.") or S("Area moved.")  | 
 | 539 | +end  | 
 | 540 | + | 
 | 541 | +minetest.register_chatcommand("move_area", {  | 
 | 542 | +	params = S("<ID>").." "..S("<X|Y|Z>").." "..S("<Amount>"),  | 
 | 543 | +	description = S("Moves an area"),  | 
 | 544 | +	func = function(name, param)  | 
 | 545 | +		return move_or_resize_area(name, param, false)  | 
 | 546 | +	end  | 
 | 547 | +})  | 
 | 548 | + | 
 | 549 | +minetest.register_chatcommand("resize_area", {  | 
 | 550 | +	params = S("<ID>").." "..S("<X|Y|Z>").." "..S("<Amount>"),  | 
 | 551 | +	description = S("Resizes an area"),  | 
 | 552 | +	func = function(name, param)  | 
 | 553 | +		return move_or_resize_area(name, param, true)  | 
 | 554 | +	end  | 
 | 555 | +})  | 
0 commit comments