minetest-mods/worldedit/worldedit_commands/safe.lua

49 lines
1.2 KiB
Lua
Raw Normal View History

2019-12-14 17:47:31 +01:00
local safe_region_callback = {}
2021-05-16 19:11:28 +02:00
--`count` is the number of nodes that would possibly be modified
2019-12-14 17:47:31 +01:00
--`callback` is a callback to run when the user confirms
2021-05-16 19:11:28 +02:00
local function safe_region(name, count, callback)
if count < 20000 then
return callback()
2019-12-14 17:47:31 +01:00
end
2021-05-16 19:11:28 +02:00
--save callback to call later
safe_region_callback[name] = callback
worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
2019-12-14 17:47:31 +01:00
end
local function reset_pending(name)
2021-05-16 19:11:28 +02:00
safe_region_callback[name] = nil
2019-12-14 17:47:31 +01:00
end
minetest.register_chatcommand("/y", {
params = "",
description = "Confirm a pending operation",
func = function(name)
2021-05-16 19:11:28 +02:00
local callback = safe_region_callback[name]
2019-12-14 17:47:31 +01:00
if not callback then
worldedit.player_notify(name, "no operation pending")
return
end
reset_pending(name)
2021-05-16 19:11:28 +02:00
callback(name)
2019-12-14 17:47:31 +01:00
end,
})
minetest.register_chatcommand("/n", {
params = "",
description = "Abort a pending operation",
func = function(name)
if not safe_region_callback[name] then
worldedit.player_notify(name, "no operation pending")
return
end
reset_pending(name)
end,
})
2021-05-16 19:11:28 +02:00
return safe_region, reset_pending