From 693fc145d5280db62d71d6ddb7322d5b10c1cbf7 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 10 Jul 2023 19:25:48 +0100 Subject: [PATCH] pos: avoid calling worldedit.marker_update unless necessary --- worldeditadditions_core/core/pos.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/worldeditadditions_core/core/pos.lua b/worldeditadditions_core/core/pos.lua index 5111e38..88d5940 100644 --- a/worldeditadditions_core/core/pos.lua +++ b/worldeditadditions_core/core/pos.lua @@ -78,16 +78,21 @@ end --- Sets pos1/pos2 in worldedit for compatibility. -- @param player_name string The name of the player to set the position for. -- @param i number The index of the position to set. --- @returns Vector3? The position to set. -local function compat_worldedit_set(player_name, i, pos) +-- @param pos Vector3 The position to set. +-- @param do_update=true bool Whether to call worldedit.marker_update() or not. +-- @returns nil +local function compat_worldedit_set(player_name, i, pos, do_update) + if do_update == nil then do_update = false end if not worldedit then return end if i == 1 and worldedit.pos1 then worldedit.pos1[player_name] = nil - if worldedit.marker_update then worldedit.marker_update(player_name) end + if do_update and worldedit.marker_update then + worldedit.marker_update(player_name) end worldedit.pos1[player_name] = pos:clone() elseif i == 2 and worldedit.pos2 then worldedit.pos2[player_name] = nil - if worldedit.marker_update then worldedit.marker_update(player_name) end + if do_update and worldedit.marker_update then + worldedit.marker_update(player_name) end worldedit.pos2[player_name] = pos:clone() end end @@ -231,7 +236,10 @@ local function pop(player_name) local last_pos = table.remove(positions[player_name]) if worldedit then if pos_count == 2 and worldedit.pos2 then worldedit.pos2[player_name] = nil - elseif pos_count == 1 and worldedit.pos1 then worldedit.pos1[player_name] = nil end + elseif pos_count == 1 and worldedit.pos1 then + worldedit.pos1[player_name] = nil + worldedit.marker_update(player_name) + end end anchor:emit("pop", { player_name = player_name, pos = last_pos, i = pos_count })