Quantcast

Fix mana/power updates

James Whitehead II [10-18-10 - 08:47]
Fix mana/power updates
Filename
PerfectRaid.lua
diff --git a/PerfectRaid.lua b/PerfectRaid.lua
index 924d7b3..ce26622 100644
--- a/PerfectRaid.lua
+++ b/PerfectRaid.lua
@@ -90,14 +90,8 @@ function PerfectRaid:Enable()
 	self:RegisterEvent("UNIT_DISPLAYPOWER")
 	self:RegisterEvent("UNIT_HEALTH")
 	self:RegisterEvent("UNIT_MAXHEALTH")
-	self:RegisterEvent("UNIT_MANA", "UNIT_MANA")
-	self:RegisterEvent("UNIT_RAGE", "UNIT_MANA")
-	self:RegisterEvent("UNIT_ENERGY", "UNIT_MANA")
-	self:RegisterEvent("UNIT_FOCUS", "UNIT_MANA")
-	self:RegisterEvent("UNIT_MAXMANA")
-	self:RegisterEvent("UNIT_MAXRAGE", "UNIT_MAXMANA")
-	self:RegisterEvent("UNIT_MAXENERGY", "UNIT_MAXMANA")
-	self:RegisterEvent("UNIT_MAXFOCUS", "UNIT_MAXMANA")
+	self:RegisterEvent("UNIT_POWER", "UNIT_POWER")
+	self:RegisterEvent("UNIT_MAXPOWER", "UNIT_MAXPOWER")
 	self:RegisterEvent("CHAT_MSG_SYSTEM")
 	self:RegisterEvent("PLAYER_ALIVE", function() self:UNIT_HEALTH("UNIT_HEALTH", "player") end)
     self:RegisterEvent("PLAYER_ENTERING_WORLD", "FullUpdate")
@@ -400,12 +394,28 @@ function PerfectRaid:UNIT_HEALTH(event, unit)
 	end
 end

-function PerfectRaid:UNIT_MANA(event, unit)
+function PerfectRaid:UNIT_POWER(event, unit, powerType)
 	if not frames[unit] then return end
-	local mana = UnitMana(unit)
-
-	for frame in pairs(frames[unit]) do
-		frame.manabar:SetValue(mana)
+    local currentType, currentToken = UnitPowerType(unit)
+    if currentToken == powerType then
+        local mana, currentPower = UnitPower(unit, currentType)
+        for frame in pairs(frames[unit]) do
+            frame.manabar:SetValue(mana)
+        end
+    end
+end
+
+function PerfectRaid:UNIT_MAXPOWER(event, unit, powerType)
+	if not frames[unit] then return end
+
+    local currentType, currentToken = UnitPowerType(unit)
+    if currentToken == powerType then
+        local max = UnitPowerMax(unit, currentType)
+        local mana = UnitPower(unit, currentType)
+        for frame in pairs(frames[unit]) do
+            frame.manabar:SetMinMaxValues(0, max)
+            self:UNIT_POWER(nil, unit, powerType)
+        end
 	end
 end

@@ -419,16 +429,6 @@ function PerfectRaid:UNIT_MAXHEALTH(event, unit)
 	end
 end

-function PerfectRaid:UNIT_MAXMANA(event, unit)
-	if not frames[unit] then return end
-	local max = UnitManaMax(unit)
-	local mana = UnitMana(unit)
-	for frame in pairs(frames[unit]) do
-		frame.manabar:SetMinMaxValues(0, max)
-		self:UNIT_MANA(nil, unit)
-	end
-end
-
 local function OnShow(frame)
 	local self = PerfectRaid
 	local unit = frame:GetAttribute("unit")
@@ -528,7 +528,7 @@ function OnAttributeChanged(frame, name, value)
 		end

 		self:UNIT_HEALTH(nil, unit)
-		self:UNIT_MANA(nil, unit)
+		self:UNIT_POWER(nil, unit)
 		self:TriggerMessage("PERFECTRAID_FRAME_LAYOUT_CHANGED");
 	end

@@ -728,8 +728,8 @@ local updateMethods = {
     "UNIT_DISPLAYPOWER",
     "UNIT_HEALTH",
     "UNIT_MAXHEALTH",
-    "UNIT_MANA",
-    "UNIT_MAXMANA",
+	"UNIT_POWER",
+	"UNIT_MAXPOWER",
 }

 function PerfectRaid:FullUpdate()