safe.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. local safe_region_callback = {}
  2. --`count` is the number of nodes that would possibly be modified
  3. --`callback` is a callback to run when the user confirms
  4. local function safe_region(name, count, callback)
  5. if count < 20000 then
  6. return callback()
  7. end
  8. --save callback to call later
  9. safe_region_callback[name] = callback
  10. worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
  11. end
  12. local function reset_pending(name)
  13. safe_region_callback[name] = nil
  14. end
  15. minetest.register_chatcommand("/y", {
  16. params = "",
  17. description = "Confirm a pending operation",
  18. func = function(name)
  19. local callback = safe_region_callback[name]
  20. if not callback then
  21. worldedit.player_notify(name, "no operation pending")
  22. return
  23. end
  24. reset_pending(name)
  25. callback(name)
  26. end,
  27. })
  28. minetest.register_chatcommand("/n", {
  29. params = "",
  30. description = "Abort a pending operation",
  31. func = function(name)
  32. if not safe_region_callback[name] then
  33. worldedit.player_notify(name, "no operation pending")
  34. return
  35. end
  36. reset_pending(name)
  37. end,
  38. })
  39. return safe_region, reset_pending