LibAuras
There is once again a function in the API to retrieve auras by name (AuraUtil.FindAuraByName), which I recommend instead of this library.
Since 8.0, the lua API no longer allows calling UnitAura(), UnitBuff, or UnitDebuff() with the name of an aura. Instead of having each addon loop through every buff or debuff every time they just want to call one, LibAuras only does so once (for each UNIT_AURA event), and shares that data across addons.
Usage
LibAuras has a very familiar interface. Ex:
local LibAuras = LibStub:GetLibrary("LibAuras")
local name, _, count = LibAuras:UnitAura("player", "buff name", "HELPFUL")
API
:UnitAura(unitId, spellIdOrName[, filter])
returns name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod, value1, value2, value3
:UnitBuff
and :UnitDebuff
work exactly the same, except they automatically add the "HELPFUL" or "HARMFUL" filters, respectively.
There are two major differences between these and the base UnitAura()
family of functions:
- LibAuras allows you to specify a spellId instead of an aura name
- There is no
rank
field returned (this also applies to the baseUnitAura()
starting in 8.0)
Caveats
LibAuras currently only supports the "HELPFUL", "HARMFUL", and "PLAYER" filters.
can this be updated for 11.x?
In reply to Blossom_Ebony:
```diff
libs/LibAuras/LibAuras.lua | 41 +++++++++++++++++++----------------------
1 file changed, 19 insertions(+), 22 deletions(-)
diff --git a/libs/LibAuras/LibAuras.lua b/libs/LibAuras/LibAuras.lua
index 26aaac1..b31cd65 100644
--- a/libs/LibAuras/LibAuras.lua
+++ b/libs/LibAuras/LibAuras.lua
@@ -131,30 +131,27 @@ addAura = function(unitId, guid, index, type)
if type == "BUFF" then filter = "HELPFUL" end
if type == "DEBUFF" then filter = "HARMFUL" end
if not filter then return end
- local name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod, value1, value2, value3 = UnitAura(unitId, index, filter)
- if not name then
+ local aura = C_UnitAuras.GetAuraDataByIndex(unitId, index, filter)
+ if not aura.name then
return false
end
- lib.AURAS[guid][type][spellId] = {}
- lib.AURAS[guid][type][spellId].name = name
- lib.AURAS[guid][type][spellId].icon = icon
- lib.AURAS[guid][type][spellId].count = count
- lib.AURAS[guid][type][spellId].debuffType = debuffType
- lib.AURAS[guid][type][spellId].duration = duration
- lib.AURAS[guid][type][spellId].expirationTime = expirationTime
- lib.AURAS[guid][type][spellId].unitCaster = unitCaster
- lib.AURAS[guid][type][spellId].canStealOrPurge = canStealOrPurge
- lib.AURAS[guid][type][spellId].nameplateShowPersonal = nameplateShowPersonal
- lib.AURAS[guid][type][spellId].canApplyAura = canApplyAura
- lib.AURAS[guid][type][spellId].isBossDebuff = isBossDebuff
- lib.AURAS[guid][type][spellId].isCastByPlayer = isCastByPlayer
- lib.AURAS[guid][type][spellId].nameplateShowAll = nameplateShowAll
- lib.AURAS[guid][type][spellId].timeMod = timeMod
- lib.AURAS[guid][type][spellId].value1 = value1
- lib.AURAS[guid][type][spellId].value2 = value2
- lib.AURAS[guid][type][spellId].value3 = value3
- if not lib.AURAS[guid][type].NAMES[name] then
- lib.AURAS[guid][type].NAMES[name] = spellId
+ lib.AURAS[guid][type][aura.spellId] = {}
+ lib.AURAS[guid][type][aura.spellId].name = aura.name
+ lib.AURAS[guid][type][aura.spellId].icon = aura.icon
+ lib.AURAS[guid][type][aura.spellId].count = aura.applications
+ lib.AURAS[guid][type][aura.spellId].debuffType = aura.dispelType
+ lib.AURAS[guid][type][aura.spellId].duration = aura.duration
+ lib.AURAS[guid][type][aura.spellId].expirationTime = aura.expirationTime
+ lib.AURAS[guid][type][aura.spellId].unitCaster = aura.source
+ lib.AURAS[guid][type][aura.spellId].canStealOrPurge = aura.isStealable
+ lib.AURAS[guid][type][aura.spellId].nameplateShowPersonal = aura.nameplateShowPersonal
+ lib.AURAS[guid][type][aura.spellId].canApplyAura = aura.canApplyAura
+ lib.AURAS[guid][type][aura.spellId].isBossDebuff = aura.isBossAura
+ lib.AURAS[guid][type][aura.spellId].isCastByPlayer = aura.isFromPlayerOrPlayerPet
+ lib.AURAS[guid][type][aura.spellId].nameplateShowAll = aura.nameplateShowAll
+ lib.AURAS[guid][type][aura.spellId].timeMod = aura.timeMod
+ if not lib.AURAS[guid][type].NAMES[aura.name] then
+ lib.AURAS[guid][type].NAMES[aura.name] = aura.spellId
end
return true
end
```
Bug: UnitBuff("player", "Power Word: Shield", "PLAYER") returns nothing even though the player has cast power word shield on themselves.
Repro:
Have two priests cast power word shield on the player. The second priest's shield causes the library to return empty for the buff even though the player has it twice (once from the player, and once from their party member) with one of the shield's matching the PLAYER filter.
In reply to Ladylag65375:
Sadly that without queryng impossible now get by ID anything, its cost a lot of power.
Doesn't return anything exception name arg currently on beta for ":UnitAura" but its fine I guess because everything other works ":UnitBuff" and ":UnitDebuff"
function TesT()
local LibAuras = LibStub:GetLibrary("LibAuras")
local ame, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod, value1, value2, value3 = LibAuras:UnitAura("player", 1044)
return duration
end
In reply to Aynni: