2023-10-23 20:52:04 +02:00
|
|
|
local S = minetest.get_translator("worldedit_commands")
|
|
|
|
|
2024-05-26 15:01:12 +02:00
|
|
|
local safe_region_limit = tonumber(minetest.settings:get("worldedit_safe_region_limit") or "20000")
|
|
|
|
|
2014-04-20 05:33:20 +02:00
|
|
|
local safe_region_callback = {}
|
2014-03-12 21:11:00 +01:00
|
|
|
|
2019-12-19 14:12:45 +01:00
|
|
|
--`count` is the number of nodes that would possibly be modified
|
2014-03-12 21:11:00 +01:00
|
|
|
--`callback` is a callback to run when the user confirms
|
2019-12-19 14:12:45 +01:00
|
|
|
local function safe_region(name, count, callback)
|
2024-05-26 15:01:12 +02:00
|
|
|
if safe_region_limit <= 0 or count < safe_region_limit then
|
2019-12-19 14:12:45 +01:00
|
|
|
return callback()
|
2014-03-12 21:11:00 +01:00
|
|
|
end
|
2019-12-19 14:12:45 +01:00
|
|
|
|
2024-05-26 15:18:13 +02:00
|
|
|
-- save callback to call later
|
2019-12-19 14:12:45 +01:00
|
|
|
safe_region_callback[name] = callback
|
2024-05-26 15:18:13 +02:00
|
|
|
|
|
|
|
local count_str = tostring(count)
|
|
|
|
-- highlight millions, 1 mln <=> 100x100x100 cube
|
|
|
|
if #count_str > 6 then
|
|
|
|
count_str = minetest.colorize("#f33", count_str:sub(1, -7)) .. count_str:sub(-6, -1)
|
|
|
|
end
|
|
|
|
|
|
|
|
local yes_cmd = minetest.colorize("#00ffff", "//y")
|
|
|
|
local no_cmd = minetest.colorize("#00ffff", "//n")
|
|
|
|
local msg = S("WARNING: this operation could affect up to @1 nodes; type @2 to continue or @3 to cancel",
|
|
|
|
count_str, yes_cmd, no_cmd)
|
|
|
|
worldedit.player_notify(name, msg, "info")
|
2014-03-12 21:11:00 +01:00
|
|
|
end
|
|
|
|
|
2017-01-31 19:52:54 +01:00
|
|
|
local function reset_pending(name)
|
2019-12-19 14:12:45 +01:00
|
|
|
safe_region_callback[name] = nil
|
2017-01-31 19:52:54 +01:00
|
|
|
end
|
|
|
|
|
2014-10-25 07:53:20 +02:00
|
|
|
minetest.register_chatcommand("/y", {
|
2014-03-12 21:11:00 +01:00
|
|
|
params = "",
|
2023-10-23 20:52:04 +02:00
|
|
|
description = S("Confirm a pending operation"),
|
2014-04-20 05:33:20 +02:00
|
|
|
func = function(name)
|
2019-12-19 14:12:45 +01:00
|
|
|
local callback = safe_region_callback[name]
|
2014-03-12 21:11:00 +01:00
|
|
|
if not callback then
|
2024-04-22 17:33:16 +02:00
|
|
|
worldedit.player_notify(name, S("no operation pending"), "error")
|
2014-03-12 21:11:00 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-09-17 23:47:29 +02:00
|
|
|
reset_pending(name)
|
2019-12-19 14:12:45 +01:00
|
|
|
callback(name)
|
2014-03-12 21:11:00 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2014-10-25 07:53:20 +02:00
|
|
|
minetest.register_chatcommand("/n", {
|
2014-03-12 21:11:00 +01:00
|
|
|
params = "",
|
2023-10-23 20:52:04 +02:00
|
|
|
description = S("Abort a pending operation"),
|
2014-04-20 05:33:20 +02:00
|
|
|
func = function(name)
|
|
|
|
if not safe_region_callback[name] then
|
2024-04-22 17:33:16 +02:00
|
|
|
worldedit.player_notify(name, S("no operation pending"), "error")
|
2014-03-12 21:11:00 +01:00
|
|
|
return
|
|
|
|
end
|
2017-09-17 23:47:29 +02:00
|
|
|
|
|
|
|
reset_pending(name)
|
2014-03-12 21:11:00 +01:00
|
|
|
end,
|
|
|
|
})
|
2015-05-17 01:52:11 +02:00
|
|
|
|
|
|
|
|
2019-12-19 14:12:45 +01:00
|
|
|
return safe_region, reset_pending
|