1818
1919worldedit .registered_commands = {}
2020
21+ local function copy_state (which , name )
22+ if which == 0 then
23+ return {}
24+ elseif which == 1 then
25+ return {
26+ worldedit .pos1 [name ] and vector .copy (worldedit .pos1 [name ])
27+ }
28+ else
29+ return {
30+ worldedit .pos1 [name ] and vector .copy (worldedit .pos1 [name ]),
31+ worldedit .pos2 [name ] and vector .copy (worldedit .pos2 [name ])
32+ }
33+ end
34+ end
35+
2136local function chatcommand_handler (cmd_name , name , param )
2237 local def = assert (worldedit .registered_commands [cmd_name ])
2338
@@ -44,29 +59,42 @@ local function chatcommand_handler(cmd_name, name, param)
4459 return
4560 end
4661
47- if def .nodes_needed then
48- local count = def .nodes_needed (name , unpack (parsed ))
49- safe_region (name , count , function ()
50- local _ , msg = def .func (name , unpack (parsed ))
51- if msg then
52- minetest .chat_send_player (name , msg )
53- end
54- end , def .require_pos ~= 2 )
55- else
56- -- no "safe region" check
62+ local run = function ()
5763 local _ , msg = def .func (name , unpack (parsed ))
5864 if msg then
5965 minetest .chat_send_player (name , msg )
6066 end
6167 end
68+
69+ if not def .nodes_needed then
70+ -- no safe region check
71+ run ()
72+ return
73+ end
74+
75+ local count = def .nodes_needed (name , unpack (parsed ))
76+ local old_state = copy_state (def .require_pos , name )
77+ safe_region (name , count , function ()
78+ local state = copy_state (def .require_pos , name )
79+ local ok = true
80+ for i , v in ipairs (state ) do
81+ ok = ok and ( (v == nil and old_state [i ] == nil ) or vector .equals (v , old_state [i ]) )
82+ end
83+ if not ok then
84+ worldedit .player_notify (name , S (" ERROR: the operation was cancelled because the region has changed." ))
85+ return
86+ end
87+
88+ run ()
89+ end , def .require_pos ~= 2 )
6290end
6391
6492-- Registers a chatcommand for WorldEdit
6593-- name = "about" -- Name of the chat command (without any /)
6694-- def = {
6795-- privs = {}, -- Privileges needed
6896-- params = "", -- Human readable parameter list (optional)
69- -- -- setting params = "" will automatically provide a parse() if not given
97+ -- -- if params = "" then a parse() implementation will automatically be provided
7098-- description = "", -- Description
7199-- require_pos = 0, -- Number of positions required to be set (optional)
72100-- parse = function(param)
0 commit comments