Skip to content

Commit dfbaa6f

Browse files
cscoder69claude
andcommitted
Never touch forbidden nameplates (dungeons/raids); measure plates in the open world only
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8f37eb2 commit dfbaa6f

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎CSCoder_QuestIndicator.lua‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ end
199199

200200
-- Quest objects need both the master switch and their own option.
201201
local function ObjectsOn() return db.active and db.objects end
202+
local UsablePlate -- defined with the icons
202203
local RefreshSoftObject, EnableObjectNameplates, RestoreObjectCVars -- soft-target objects
203204
local RefreshControls, UpdatePreview, UpdateMinimapButton, UpdateGates, LayoutTabs -- options UI
204205
local settingsScroll -- the scrolling settings page
@@ -647,6 +648,19 @@ local function UpdateCombatAlpha()
647648
for _, f in pairs(icons) do f:SetAlpha(alpha) end
648649
end
649650

651+
-- A unit's nameplate if the addon may use it. In dungeons and raids the game can hand out
652+
-- "forbidden" plates (other addons may not touch them): anchoring to one, or measuring it,
653+
-- raises errors, so those count as no plate.
654+
function UsablePlate(unit)
655+
local plate = C_NamePlate and C_NamePlate.GetNamePlateForUnit and C_NamePlate.GetNamePlateForUnit(unit)
656+
if not plate then return nil end
657+
if plate.IsForbidden then
658+
local ok, forbidden = pcall(plate.IsForbidden, plate)
659+
if not ok or forbidden then return nil end
660+
end
661+
return plate
662+
end
663+
650664
-- Inside a dungeon or raid (party / raid instance), with "Hide in dungeons and raids" on.
651665
local function InstanceHidden()
652666
if not (db.hideInInstances and IsInInstance) then return false end
@@ -655,7 +669,7 @@ local function InstanceHidden()
655669
end
656670

657671
local function Refresh(unit)
658-
local plate = C_NamePlate and C_NamePlate.GetNamePlateForUnit(unit)
672+
local plate = UsablePlate(unit)
659673
if db.active and db.enabled and plate and not InstanceHidden() then
660674
local needed, kind, progress = IsQuestMob(unit)
661675
if needed then ShowIcon(unit, plate, kind, progress) return end
@@ -672,7 +686,7 @@ local function RefreshAll()
672686
end
673687
RefreshSoftObject()
674688
for unit in pairs(icons) do
675-
if not C_NamePlate.GetNamePlateForUnit(unit) then HideIcon(unit) end
689+
if not UsablePlate(unit) then HideIcon(unit) end
676690
end
677691
end
678692

@@ -856,7 +870,7 @@ function RefreshSoftObject()
856870
local isQuest, kind, progress = false, nil, nil
857871
if UnitExists(SOFT) then isQuest, kind, progress = IsQuestObject(SOFT) end
858872
UpdateGate(isQuest)
859-
local plate = C_NamePlate and C_NamePlate.GetNamePlateForUnit(SOFT)
873+
local plate = UsablePlate(SOFT)
860874
if isQuest and plate then
861875
if icons[SOFT] and icons[SOFT]:GetParent() ~= plate then HideIcon(SOFT) end
862876
ShowIcon(SOFT, plate, kind, progress)
@@ -2897,8 +2911,8 @@ end
28972911

28982912
function MeasurePlate(unit, force)
28992913
if (plateMeasured and not force) or not (root and C_NamePlate and C_NamePlate.GetNamePlateForUnit) then return end
2900-
local plate = C_NamePlate.GetNamePlateForUnit(unit)
2901-
if not plate then return end
2914+
local plate = UsablePlate(unit)
2915+
if not plate or (IsInInstance and IsInInstance()) then return end -- measured in the open world only
29022916
local w, h = Read(plate, "GetSize")
29032917
local eff = Read(plate, "GetEffectiveScale")
29042918
if not (w and h and eff) or w <= 0 or h <= 0 then return end

‎tools/wowmock.lua‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ do
197197
for _, f in ipairs(frames) do if rawget(f, "unit") == "nameplate1" and f._shown then shownInDungeon = true end end
198198
print("quest: icon hidden in a dungeon", not shownInDungeon)
199199
env.IsInInstance = nil
200+
201+
-- A forbidden plate (dungeons can hand them out) is never touched, even with the option off.
202+
profile.hideInInstances = false
203+
rawset(mobPlate, "IsForbidden", function() return true end)
204+
try("forbidden plate", eventFrame._scripts.OnEvent, eventFrame, "NAME_PLATE_UNIT_REMOVED", "nameplate1")
205+
try("forbidden plate", eventFrame._scripts.OnEvent, eventFrame, "NAME_PLATE_UNIT_ADDED", "nameplate1")
206+
local onForbidden = false
207+
for _, f in ipairs(frames) do if rawget(f, "unit") == "nameplate1" and f._shown then onForbidden = true end end
208+
print("quest: forbidden plate left alone", not onForbidden)
209+
profile.hideInInstances = true
200210
env.UnitExists = function() return false end
201211
env.C_NamePlate.GetNamePlates = function() return {} end
202212
env.C_NamePlate.GetNamePlateForUnit = function() return nil end

0 commit comments

Comments
 (0)