@@ -6,24 +6,33 @@ local AFK = Grid2.statusPrototype:new("afk")
6
6
7
7
local Grid2 = Grid2
8
8
local GetTime = GetTime
9
+ local UnitGUID = UnitGUID
9
10
local UnitIsAFK = UnitIsAFK
10
11
11
12
local afk_cache = setmetatable ({}, {__index = function (t ,k ) local v = GetTime (); t [k ]= v ; return v end })
12
13
13
14
AFK .GetColor = Grid2 .statusLibrary .GetColor
14
15
15
- function AFK : UpdateUnit (_ , unit )
16
+ local function UpdateUnit (_ , unit )
16
17
if unit then
17
- afk_cache [unit ] = nil
18
- self :UpdateIndicators (unit )
18
+ if not UnitIsAFK (unit ) then -- only clear cache, afk_cache is already assigned when metatable lookup fails in GetStartTime()
19
+ afk_cache [ UnitGUID (unit ) ] = nil
20
+ end
21
+ AFK :UpdateIndicators (unit )
22
+ end
23
+ end
24
+
25
+ function AFK :ZONE_CHANGED_NEW_AREA ()
26
+ for unit in Grid2 :IterateRosterUnits () do
27
+ UpdateUnit (nil ,unit )
19
28
end
20
29
end
21
30
22
31
function AFK :OnEnable ()
23
- self :RegisterEvent (" PLAYER_FLAGS_CHANGED" , " UpdateUnit" )
24
- self :RegisterEvent (" ZONE_CHANGED_NEW_AREA" , " UpdateAllUnits " )
25
- self :RegisterEvent (" READY_CHECK" , " UpdateAllUnits " )
26
- self :RegisterEvent (" READY_CHECK_FINISHED" , " UpdateAllUnits " )
32
+ self :RegisterEvent (" PLAYER_FLAGS_CHANGED" , UpdateUnit )
33
+ self :RegisterEvent (" ZONE_CHANGED_NEW_AREA" )
34
+ self :RegisterEvent (" READY_CHECK" , " ZONE_CHANGED_NEW_AREA " )
35
+ self :RegisterEvent (" READY_CHECK_FINISHED" , " ZONE_CHANGED_NEW_AREA " )
27
36
end
28
37
29
38
function AFK :OnDisable ()
@@ -39,7 +48,7 @@ function AFK:IsActive(unit)
39
48
end
40
49
41
50
function AFK :GetStartTime (unit )
42
- return afk_cache [unit ]
51
+ return afk_cache [ UnitGUID ( unit ) ]
43
52
end
44
53
45
54
local text = L [" AFK" ]
0 commit comments