Skip to content

Commit

Permalink
Fixed an issue where name changing toys would break addon communication
Browse files Browse the repository at this point in the history
  • Loading branch information
linaori committed Aug 1, 2022
1 parent 76be75d commit b419a43
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ globals = {
'UnitFullName',
'GetUnitName',
'GetRealmName',
'UnitNameUnmodified',
'GetNumGroupMembers',
'GetBattlefieldStatus',
'GetMaxBattlefieldID',
Expand Down
8 changes: 4 additions & 4 deletions BattlegroundTools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local CreateFrame = CreateFrame
local GetTime = GetTime
local ReplaceIconAndGroupExpressions = C_ChatInfo.ReplaceIconAndGroupExpressions
local GetInstanceInfo = GetInstanceInfo
local GetUnitName = GetUnitName
local GetRealUnitName = Namespace.Utils.GetRealUnitName
local PromoteToLeader = PromoteToLeader
local PlaySound = PlaySound
local UnitIsGroupLeader = UnitIsGroupLeader
Expand Down Expand Up @@ -446,7 +446,7 @@ function Module:GetZoneId(zoneId)
end

function Private.OnAcknowledgeWantBattlegroundLead(_, _, _, sender)
if sender == GetUnitName('player', true) then return end
if sender == GetRealUnitName('player') then return end

local mem = Memory.WantBattlegroundLead
if not mem.ackTimer then return end
Expand Down Expand Up @@ -482,7 +482,7 @@ function Private.SendAcknowledgeWantBattlegroundLead()
end

function Private.OnWantBattlegroundLead(_, _, _, sender)
if sender == GetUnitName('player', true) then return end
if sender == GetRealUnitName('player') then return end
if not UnitIsGroupLeader('player') then return end

local mem = Memory.WantBattlegroundLead
Expand Down Expand Up @@ -529,7 +529,7 @@ function Private.SendWantBattlegroundLead()
if channel == Channel.Whisper then return end

if Namespace.Database.profile.BattlegroundTools.WantBattlegroundLead.enableManualRequest then
local groupLeader = GetUnitName(GetGroupLeaderUnit(), true)
local groupLeader = GetRealUnitName(GetGroupLeaderUnit())
if mem.ackLeader == nil or groupLeader ~= mem.ackLeader then
-- re-buffer the timer each time the leader changes to give them enough time to reply
if mem.ackTimer then Module:CancelTimer(mem.ackTimer) end
Expand Down
4 changes: 2 additions & 2 deletions Communication.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local LibCompress = Namespace.Libs.LibCompress
local Encoder = LibCompress:GetAddonEncodeTable()

local GroupType = Namespace.Utils.GroupType
local GetUnitName = GetUnitName
local GetRealUnitName = Namespace.Utils.GetRealUnitName

local Channel = {
Raid = 'RAID',
Expand Down Expand Up @@ -39,5 +39,5 @@ function Namespace.Communication.GetMessageDestination()
if currentType == GroupType.Raid then return Channel.Raid, nil end
if currentType == GroupType.Party then return Channel.Party, nil end

return Channel.Whisper, GetUnitName('player', true)
return Channel.Whisper, GetRealUnitName('player')
end
2 changes: 1 addition & 1 deletion Debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local Private, _, Namespace = {}, ...
Namespace.Debug = {}
--@debug@
Namespace.Debug.enabled = true
Namespace.Meta.version = '1.6.6-dev'
Namespace.Meta.version = '1.6.7-dev'
--@end-debug@

local type, pairs, tostring, print, concat, select = type, pairs, tostring, print, table.concat, select
Expand Down
10 changes: 5 additions & 5 deletions PlayerData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local ReadyCheckState = Namespace.Utils.ReadyCheckState
local BattlegroundStatus = Namespace.Utils.BattlegroundStatus
local GroupType = Namespace.Utils.GroupType
local GetGroupType = Namespace.Utils.GetGroupType
local GetUnitName = GetUnitName
local GetRealUnitName = Namespace.Utils.GetRealUnitName
local UnitIsPlayer = UnitIsPlayer
local UnitGUID = UnitGUID
local UnitExists = UnitExists
Expand Down Expand Up @@ -69,7 +69,7 @@ function Namespace.PlayerData.RebuildPlayerData()
local data = Memory.AllPlayerData[dataIndex]
if not data then
data = {
name = GetUnitName(unit, true),
name = GetRealUnitName(unit),
readyState = ReadyCheckState.Nothing,
deserterExpiry = -1,
units = {primary = unit, [unit] = true},
Expand All @@ -79,7 +79,7 @@ function Namespace.PlayerData.RebuildPlayerData()
Memory.AllPlayerData[dataIndex] = data
else
-- always refresh the name whenever possible
data.name = GetUnitName(unit, true)
data.name = GetRealUnitName(unit)

if not data.units.primary then
data.units.primary = unit
Expand All @@ -106,7 +106,7 @@ function Namespace.PlayerData.GetPlayerDataByUnit(unit)

-- fallback to getting the name of the unit in case of weird scenarios
-- where "target" or "nameplate1" is sent
local name = GetUnitName(unit, true)
local name = GetRealUnitName(unit)
if not name then return nil end

return Namespace.PlayerData.GetPlayerDataByName(name)
Expand All @@ -115,7 +115,7 @@ end
function Namespace.PlayerData.GetPlayerDataByName(name)
for _, data in pairs(Memory.AllPlayerData) do
if data.units.primary and (data.name == UNKNOWNOBJECT or data.name == nil) then
data.name = GetUnitName(data.units.primary, true)
data.name = GetRealUnitName(data.units.primary)
end

if data.name == name then
Expand Down
8 changes: 4 additions & 4 deletions QueueTools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ local GetNumGroupMembers = GetNumGroupMembers
local GetBattlefieldStatus = GetBattlefieldStatus
local GetMaxBattlefieldID = GetMaxBattlefieldID
local GetLFGRoleUpdate = GetLFGRoleUpdate
local GetUnitName = GetUnitName
local GetRealUnitName = Namespace.Utils.GetRealUnitName
local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo
local UnitClass = UnitClass
local UnitDebuff = UnitDebuff
Expand Down Expand Up @@ -204,7 +204,7 @@ function Private.CreateTableRow(index, data)

if data.name == UNKNOWNOBJECT or data.name == nil then
-- try to update the name as it wasn't available on initial check
data.name = GetUnitName(data.units.primary, true)
data.name = GetRealUnitName(data.units.primary)
end

local name, color
Expand Down Expand Up @@ -442,7 +442,7 @@ function Private.OnSyncData(_, text, _, sender)
end

function Private.OnReadyCheckHeartbeat(_, text, _, sender)
if sender == GetUnitName('player', true) then return end
if sender == GetRealUnitName('player') then return end

local acceptReadyCheck = function (skipVisibility)
if not skipVisibility and not _G.ReadyCheckFrameYesButton:IsVisible() then return end
Expand Down Expand Up @@ -525,7 +525,7 @@ function Private.OnDeclineBattleground(_, _, _, sender)
data.battlegroundStatus = BattlegroundStatus.Declined
end

if sender ~= GetUnitName('player', true) and IsLeaderOrAssistant(data.units.primary) then
if sender ~= GetRealUnitName('player') and IsLeaderOrAssistant(data.units.primary) then
Private.DisableEntryButton()
end

Expand Down
8 changes: 8 additions & 0 deletions Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local IsInRaid = IsInRaid
local IsInGroup = IsInGroup
local UnitIsGroupLeader = UnitIsGroupLeader
local UnitIsGroupAssistant = UnitIsGroupAssistant
local UnitNameUnmodified = UnitNameUnmodified
local LE_PARTY_CATEGORY_HOME = LE_PARTY_CATEGORY_HOME
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
local floor = math.floor
Expand Down Expand Up @@ -135,3 +136,10 @@ end
function Namespace.Utils.IsLeaderOrAssistant(unit)
return UnitIsGroupLeader(unit) or UnitIsGroupAssistant(unit)
end

function Namespace.Utils.GetRealUnitName(unit)
local name, realm = UnitNameUnmodified(unit)
if realm == nil then return name end

return name .. '-' .. realm
end

0 comments on commit b419a43

Please sign in to comment.