Skip to content

Commit 5c6cabf

Browse files
sfan5MoNTE48
authored andcommitted
Abort a delayed operation if positions change
fixes #236
1 parent 38f4715 commit 5c6cabf

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

worldedit_commands/init.lua

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ end
1818

1919
worldedit.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+
2136
local 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)
6290
end
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)

worldedit_commands/locale/template.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Can use WorldEdit commands=
1919
no region selected=
2020
no position 1 selected=
2121
invalid usage=
22+
ERROR: the operation was cancelled because the region has changed.=
2223
Could not open file "@1"=
2324
Invalid file format!=
2425
Schematic was created with a newer version of WorldEdit.=

worldedit_commands/locale/worldedit_commands.de.tr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Can use WorldEdit commands=Kann WorldEdit-Befehle benutzen
3030
no region selected=Kein Gebiet ausgewählt
3131
no position 1 selected=Keine Position 1 ausgewählt
3232
invalid usage=Ungültige Verwendung
33+
ERROR: the operation was cancelled because the region has changed.=FEHLER: Der Vorgang wurde abgebrochen, weil das Gebiet verändert wurde.
3334
Could not open file "@1"=Konnte die Datei „@1“ nicht öffnen
3435
Invalid file format!=Ungültiges Dateiformat!
3536
Schematic was created with a newer version of WorldEdit.=Schematic wurde mit einer neueren Version von WorldEdit erstellt.

0 commit comments

Comments
 (0)