Fix //y support with the new worldedit

This commit is contained in:
HybridDog 2021-07-29 19:43:34 +02:00
parent 634c07156d
commit f6197c0886

@ -302,15 +302,8 @@ end
----------------------- Functions common to other ones ------------------------- ----------------------- Functions common to other ones -------------------------
-- Catch confirmation requests (/y or /n follows) -- Remember the last command overridings for //y
local y_pending = {} local y_pending = {}
local we_notify = worldedit.player_notify
function worldedit.player_notify(name, msg)
if msg:sub(1, 43) == "WARNING: this operation could affect up to " then
y_pending[name] = true
end
return we_notify(name, msg)
end
override_chatcommand("/n", override_chatcommand("/n",
function() function()
@ -321,35 +314,36 @@ override_chatcommand("/n",
override_chatcommand("/y", override_chatcommand("/y",
function(...) function(...)
local t = y_pending[command_invoker] local t = y_pending[command_invoker]
if type(t) == "table" if t and t.before then
and t.before then
t.before(...) t.before(...)
end end
end, end,
function(...) function(...)
local t = y_pending[command_invoker] local t = y_pending[command_invoker]
if type(t) == "table" if t and t.after then
and t.after then
t.after(...) t.after(...)
end end
y_pending[command_invoker] = nil y_pending[command_invoker] = nil
end end
) )
local function override_cc_with_confirm(cname, func_before, actual_func_after) local function override_cc_with_confirm(cname, func_before, func_after)
-- remember the functions for /y if needed -- Remember the functions for //y if needed
local function func_after(...) -- func_before and func_after are always executed before and after
if y_pending[command_invoker] then -- the command cname.
y_pending[command_invoker] = {before = func_before, -- func_before and func_after are executed a second time if the
after = func_after} -- player then calls //y (unless the player calls //n before //y).
end -- Therefore these two functions should only do temporary overridings of
return actual_func_after(...) -- relevant functions, e.g. worldedit.cube.
local function func_after_wrap(...)
y_pending[command_invoker] = {before = func_before, after = func_after}
return func_after(...)
end end
return override_chatcommand(cname, func_before, func_after) return override_chatcommand(cname, func_before, func_after_wrap)
end end
-- override the worldedit vmanip finish function to catch the data table -- Override the worldedit vmanip finish function to catch the data table
local we_data = false local we_data = false
local we_manip_end = worldedit.manip_helpers.finish local we_manip_end = worldedit.manip_helpers.finish
function worldedit.manip_helpers.finish(manip, data) function worldedit.manip_helpers.finish(manip, data)