Skip to content

Commit 66d5f4e

Browse files
committed
Make //stack and //stack2 check max_size
1 parent b952e9d commit 66d5f4e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

worldedit_commands/init.lua

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ worldedit.inspect = {}
1010
worldedit.prob_pos = {}
1111
worldedit.prob_list = {}
1212

13-
local safe_region, reset_pending, safe_area = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
13+
local safe_region, reset_pending, safe_area, max_size =
14+
dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua")
1415

1516
function worldedit.player_notify(name, message)
1617
minetest.chat_send_player(name, "WorldEdit -!- " .. message, false)
@@ -52,7 +53,7 @@ local function chatcommand_handler(cmd_name, name, param)
5253
end
5354
end
5455

55-
local parsed = {def.parse(param)}
56+
local parsed = {def.parse(param, name)}
5657
local success = table.remove(parsed, 1)
5758
if not success then
5859
worldedit.player_notify(name, parsed[1] or S("invalid usage"))
@@ -1138,12 +1139,20 @@ worldedit.register_command("stack", {
11381139
category = S("Transformations"),
11391140
privs = {worldedit=true},
11401141
require_pos = 2,
1141-
parse = function(param)
1142+
parse = function(param, name)
11421143
local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$")
11431144
repetitions = tonumber(repetitions)
11441145
if found == nil or math.abs(repetitions) > 100 then
11451146
return false
11461147
end
1148+
1149+
-- Does this need a separate error or is the 128x128x128 message fine?
1150+
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
1151+
if math.abs((math.abs(pos2[axis] - pos1[axis]) + 1) * repetitions) > max_size then
1152+
return false, S("Your selected area is too big, you can only select areas up to @1 × @2 × @3",
1153+
max_size, max_size, max_size)
1154+
end
1155+
11471156
return true, axis, repetitions
11481157
end,
11491158
nodes_needed = function(name, axis, repetitions)
@@ -1170,7 +1179,7 @@ worldedit.register_command("stack2", {
11701179
category = S("Transformations"),
11711180
privs = {worldedit=true},
11721181
require_pos = 2,
1173-
parse = function(param)
1182+
parse = function(param, name)
11741183
local repetitions, incs = param:match("(%d+)%s*(.+)")
11751184
repetitions = tonumber(repetitions)
11761185
if repetitions == nil or math.abs(repetitions) > 100 then
@@ -1181,6 +1190,14 @@ worldedit.register_command("stack2", {
11811190
return false, S("invalid increments: @1", param)
11821191
end
11831192

1193+
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
1194+
for _, axis in ipairs({"x", "y", "z"}) do
1195+
if math.abs((math.abs(pos2[axis] - pos1[axis]) + 1) * repetitions) > max_size then
1196+
return false, S("Your selected area is too big, you can only select areas up to @1 × @2 × @3",
1197+
max_size, max_size, max_size)
1198+
end
1199+
end
1200+
11841201
return true, tonumber(repetitions), vector.new(tonumber(x), tonumber(y), tonumber(z))
11851202
end,
11861203
nodes_needed = function(name, repetitions, offset)

worldedit_commands/safe.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ local function safe_area(name, pos1, pos2)
9999
return true
100100
end
101101

102-
return safe_region, reset_pending, safe_area
102+
return safe_region, reset_pending, safe_area, max_size

0 commit comments

Comments
 (0)