1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-11-15 07:00:17 +01:00
Minetest-WorldEdit/worldedit_commands/safe.lua

51 lines
1.2 KiB
Lua
Raw Normal View History

2023-10-23 20:52:04 +02:00
local S = minetest.get_translator("worldedit_commands")
local safe_region_callback = {}
2019-12-19 14:12:45 +01:00
--`count` is the number of nodes that would possibly be modified
--`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)
2020-10-06 13:53:22 +02:00
if count < 20000 then
2019-12-19 14:12:45 +01:00
return callback()
end
2019-12-19 14:12:45 +01:00
--save callback to call later
safe_region_callback[name] = callback
2023-10-23 20:52:04 +02:00
worldedit.player_notify(name, S("WARNING: this operation could affect up to @1 nodes; type //y to continue or //n to cancel", count))
end
local function reset_pending(name)
2019-12-19 14:12:45 +01:00
safe_region_callback[name] = nil
end
minetest.register_chatcommand("/y", {
params = "",
2023-10-23 20:52:04 +02:00
description = S("Confirm a pending operation"),
func = function(name)
2019-12-19 14:12:45 +01:00
local callback = safe_region_callback[name]
if not callback then
2023-10-23 20:52:04 +02:00
worldedit.player_notify(name, S("no operation pending"))
return
end
reset_pending(name)
2019-12-19 14:12:45 +01:00
callback(name)
end,
})
minetest.register_chatcommand("/n", {
params = "",
2023-10-23 20:52:04 +02:00
description = S("Abort a pending operation"),
func = function(name)
if not safe_region_callback[name] then
2023-10-23 20:52:04 +02:00
worldedit.player_notify(name, S("no operation pending"))
return
end
reset_pending(name)
end,
})
2015-05-17 01:52:11 +02:00
2019-12-19 14:12:45 +01:00
return safe_region, reset_pending