Lua Code:
local whitelist = {
[116841] = "player", --Tiger's Lust
[228287] = "player", --Mark of the Crane
[115078] = "all", --Paralysis
}
local function replacefilter(unit)
C_NamePlate.GetNamePlateForUnit(unit).UnitFrame.BuffFrame.ShouldShowBuff=function(self,name,caster,nameplateShowPersonal,nameplateShowAll,duration)
if name then
local isPlayer=UnitIsUnit(self.unit,"player")
local isEnemy=UnitCanAttack(self.unit,"player")
local filter=isPlayer and "HELPFUL" or "HARMFUL"
if isPlayer or isEnemy then
for i=1,BUFF_MAX_DISPLAY do
local spellName,_,_,_,spellDuration,_,spellCaster,_,_,spellId=UnitAura(self.unit,i,filter)
if not spellName then break end
if name==spellName and caster==spellCaster and duration==spellDuration then
if whitelist[spellId]==caster or whitelist[spellId]=="all" then
return true
end
end
end
else
return nameplateShowAll or (nameplateShowPersonal and (caster=="player" or caster=="pet" or caster=="vehicle"))
end
end
return false
end
end
local f=CreateFrame("frame")
f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
f:SetScript("OnEvent",function(_,_,unit) replacefilter(unit) end)
I had a go at reorganizing the code. Some notes:
- Filtering friendly at function replacement won't work, since all 40 nameplate frames will eventually get the replacement due to frame pooling, so you have to filter within the replacement function.
- Additionally, you don't have to worry about touching instanced friendly nameplates, separate events deal with separate secure frames while still maintaining a max of 40 nameplates active at once (e.g. FORBIDDEN_NAME_PLATE_CREATED)
- The original ShouldShowBuff has a name==nil escape, which I think should still be included.
- Since this is a usermade whitelist, INCLUDE_NAME_PLATE_ONLY should be dropped, or you may end up having an aura you want not show up if Blizzard decided it shouldn't show on nameplates.
- From my experience with a personal addon dealing with attached nameplate frames, UnitIsFriend is not consistent with neutral units, so UnitCanAttack is used instead.
- Finally, the long return line is from the original ShouldShowBuff, allowing friendly nameplates affected by this replaced function to behave as Blizzard's code intended.
NAME_PLATE_CREATED happens before UnitFrame is added, so stick with the original UNIT_ADDED event