From 6702c9168ad6e58091884b2fb429e687ac808e2e Mon Sep 17 00:00:00 2001 From: Dusk-92 Date: Thu, 3 Sep 2026 16:05:06 +0200 Subject: [PATCH] Gate optimized nameplate paths on reload-safe ClassicAPI --- api.lua | 12 ++++++++++++ libs/libnameplate.lua | 3 +-- libs/libunitscan.lua | 3 +-- mods/nameplate-castbar.lua | 8 ++++---- mods/nameplate-classcolor.lua | 4 +--- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/api.lua b/api.lua index 12265b2..3716d31 100644 --- a/api.lua +++ b/api.lua @@ -71,6 +71,18 @@ API.mapexploration = type(_G.C_MapExplorationInfo) == "table" API.eventutils = type(_G.C_EventUtils) == "table" and type(_G.C_EventUtils.IsEventValid) == "function" + +-- ClassicAPI v1.12.5 made nameplate lifecycle events reload-safe by clearing +-- and rebuilding their token/wrapper state around /reload. Older builds can +-- expose the same event names without those guarantees, so keep them on the +-- historical ShaguTweaks discovery path instead of opting into the optimized +-- event-driven path. +API.nameplateevents = API.nameplates + and API.classicapi_version >= 11205 + and API.eventutils + and _G.C_EventUtils.IsEventValid("NAME_PLATE_UNIT_ADDED") + and _G.C_EventUtils.IsEventValid("NAME_PLATE_UNIT_REMOVED") + API.modifierkeys = type(_G.IsLeftShiftKeyDown) == "function" and type(_G.IsRightShiftKeyDown) == "function" and type(_G.IsLeftControlKeyDown) == "function" diff --git a/libs/libnameplate.lua b/libs/libnameplate.lua index 96b556a..5389fa2 100644 --- a/libs/libnameplate.lua +++ b/libs/libnameplate.lua @@ -100,8 +100,7 @@ local function ScheduleDiscovery() end local function HasClassicNameplateEvents() - return API and API.nameplates and API.eventutils and _G.C_EventUtils - and _G.C_EventUtils.IsEventValid("NAME_PLATE_UNIT_ADDED") + return API and API.nameplateevents end function libnameplate:HasConsumers() diff --git a/libs/libunitscan.lua b/libs/libunitscan.lua index 632cd5f..d0d04fb 100644 --- a/libs/libunitscan.lua +++ b/libs/libunitscan.lua @@ -427,8 +427,7 @@ local passiveChatEvents = { ["CHAT_MSG_WHISPER"] = true, } -local useNameplateUnitEvents = API and API.eventutils and _G.C_EventUtils - and _G.C_EventUtils.IsEventValid("NAME_PLATE_UNIT_ADDED") +local useNameplateUnitEvents = API and API.nameplateevents libunitscan:RegisterEvent("PLAYER_ENTERING_WORLD") libunitscan:RegisterEvent("PLAYER_LOGOUT") diff --git a/mods/nameplate-castbar.lua b/mods/nameplate-castbar.lua index 26e1b91..aef1dc1 100644 --- a/mods/nameplate-castbar.lua +++ b/mods/nameplate-castbar.lua @@ -320,8 +320,7 @@ module.enable = function(self) local listener = CreateFrame("Frame") local eventValid = API and API.eventutils and _G.C_EventUtils and _G.C_EventUtils.IsEventValid - if eventValid and _G.C_EventUtils.IsEventValid("NAME_PLATE_UNIT_ADDED") - and _G.C_EventUtils.IsEventValid("NAME_PLATE_UNIT_REMOVED") then + if API and API.nameplateevents and API.casts then listener:RegisterEvent("NAME_PLATE_UNIT_ADDED") listener:RegisterEvent("NAME_PLATE_UNIT_REMOVED") useClassicNameplateTokens = true @@ -339,7 +338,7 @@ module.enable = function(self) } local hasClassicCastEvents = false - if eventValid then + if eventValid and useClassicNameplateTokens then for _, eventName in pairs(castEvents) do if _G.C_EventUtils.IsEventValid(eventName) then listener:RegisterEvent(eventName) @@ -373,7 +372,8 @@ module.enable = function(self) end local unit = arg1 - if unit and string.find(unit, "^nameplate%d+$") then + if useClassicNameplateTokens and unit + and string.find(unit, "^nameplate%d+$") then local plate = platesByUnit[unit] or AttachUnit(unit) if plate then RefreshPlate(plate) end end diff --git a/mods/nameplate-classcolor.lua b/mods/nameplate-classcolor.lua index cd8c022..62147e3 100644 --- a/mods/nameplate-classcolor.lua +++ b/mods/nameplate-classcolor.lua @@ -16,9 +16,7 @@ module.enable = function(self) local colorsByName = {} local colorsVersion = 0 - local useClassicTokens = API and API.eventutils and _G.C_EventUtils - and _G.C_EventUtils.IsEventValid("NAME_PLATE_UNIT_ADDED") - and _G.C_EventUtils.IsEventValid("NAME_PLATE_UNIT_REMOVED") + local useClassicTokens = API and API.nameplateevents if useClassicTokens then local listener = CreateFrame("Frame")