Make //unmark WEA-aware

Backwards compatibility with WE is maintained.
This commit is contained in:
Starbeamrainbowlabs 2023-07-09 19:44:31 +01:00
parent e916057133
commit 3bfc62be24
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
5 changed files with 57 additions and 2 deletions

@ -20,6 +20,7 @@ dofile(we_cmdpath.."spush.lua")
dofile(we_cmdpath.."srect.lua")
dofile(we_cmdpath.."sshift.lua")
dofile(we_cmdpath.."sstack.lua")
dofile(we_cmdpath.."unmark.lua")
-- Aliases
worldedit.alias_command("sfac", "sfactor")

@ -0,0 +1,32 @@
local weac = worldeditadditions_core
local worldedit_unmark
if minetest.registered_chatcommands["/unmark"] then
worldedit_unmark = minetest.registered_chatcommands["/unmark"].func
end
local function do_unmark(name, params_text)
-- Hide the WorldEdit marker, if appropriate
if type(worldedit_unmark) == "function" then
worldedit_unmark(name, params_text)
end
-- Hide the WorldEditAdditions marker
weac.pos.unmark(name)
end
if minetest.registered_chatcommands["/unmark"] then
minetest.override_chatcommand("/unmark", {
params = "",
description = "Hide the markers for the defined region (and any other positions), but do not remove the points themselves.",
func = do_unmark
})
else
minetest.register_chatcommand("/unmark", {
params = "",
description = "Hide the markers for the defined region (and any other positions), but do not remove the points themselves.",
privs = { worldedit = true },
func = do_unmark
})
end

@ -250,6 +250,14 @@ local function push(player_name, pos)
return #positions[player_name]
end
--- Hides the visual markers for the given player's positions and defined region, but does not clear the points.
-- @param player_name string The name of the player to operate on.
local function unmark(player_name)
anchor:emit("unmark", {
player_name = player_name
})
end
anchor = wea_c.EventEmitter.new({
get = get,
@ -265,7 +273,8 @@ anchor = wea_c.EventEmitter.new({
set1 = set1,
set2 = set2,
set_all = set_all,
compat_worldedit_get = compat_worldedit_get
unmark = unmark,
compat_worldedit_get = compat_worldedit_get,
})
anchor.debug = false

@ -82,4 +82,16 @@ wea_c.pos:addEventListener("clear", function(event)
worldedit.marker_update(event.player_name)
end
position_entities[event.player_name] = nil
end)
wea_c.pos:addEventListener("unmark", function(event)
ensure_player(event.player_name)
if #position_entities[event.player_name] > 0 then
for _, entity in pairs(position_entities[event.player_name]) do
wea_c.entities.pos_marker.delete(entity)
end
end
-- Note that this function is NOT WorldEdit compatible, because it is only called through our override of WorldEdit's `//unmark`, and WorldEdit doesn't have an API function to call to unmark and everything is complicated.
end)

@ -69,4 +69,5 @@ end
weac.pos:addEventListener("set", handle_event)
weac.pos:addEventListener("pop", handle_event)
weac.pos:addEventListener("push", handle_event)
weac.pos:addEventListener("clear", do_delete)
weac.pos:addEventListener("clear", do_delete)
weac.pos:addEventListener("unmark", do_delete)