Skip to content

Commit

Permalink
fix possibility of wrong returns if units didn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Jodsderechte committed Aug 14, 2024
1 parent f1ce865 commit dcdfd15
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ function lib.IsCharInBnetDatabase(name)
end
---returns true if custom name exists for char or btag, otherwise returns nil
---@param name string
---@return boolean? exists
---@return boolean exists
function lib.IsInBnetDatabase(name)
assert(name, "CustomNames: Can't check if Name is in BnetDatabase (name is nil)")
if CharToBnetDB[name] then
return true
elseif BnetDB[name] then
return true
else
return nil
return false
end
end

Expand Down Expand Up @@ -172,7 +172,7 @@ end
---@return string? name
---@return string? realm
function lib.UnitName(unit)
if not unit or not UnitExists(unit) then return nil,nil end
if not unit or not UnitExists(unit) then return UnitName(unit) end
local unitName, unitRealm = UnitName(unit)
local nameToCheck = unitName .. "-" .. (unitRealm or NormalizedRealmName())
local customName = lib.Get(nameToCheck)
Expand All @@ -187,7 +187,7 @@ end
---@return string? name
---@return string? realm
function lib.UnitNameUnmodified(unit)
if not unit or not UnitExists(unit) then return nil,nil end
if not unit or not UnitExists(unit) then return UnitNameUnmodified(unit) end
local unitName, unitRealm = UnitNameUnmodified(unit)
local nameToCheck = unitName .. "-" .. (unitRealm or NormalizedRealmName())
local customName = lib.Get(nameToCheck)
Expand All @@ -202,7 +202,7 @@ end
---@return string? name
---@return string? realm
function lib.UnitFullName(unit)
if not unit or not UnitExists(unit) then return nil,nil end
if not unit or not UnitExists(unit) then return UnitFullName(unit) end
local unitName, unitRealm = UnitFullName(unit)
local nameToCheck
if UnitIsPlayer(unit) then
Expand All @@ -222,15 +222,17 @@ end
---@param showServerName boolean
---@return string? name
function lib.GetUnitName(unit,showServerName)
if not unit or not UnitExists(unit) then return nil end
if not unit or not UnitExists(unit) then return GetUnitName(unit, showServerName) end
local unitName, unitRealm = UnitFullName(unit)
local nameToCheck
if UnitIsPlayer(unit) then
nameToCheck = unitName .. "-" .. (unitRealm or NormalizedRealmName())
else
nameToCheck= unitName
end
if not nameToCheck then return nil end
if not nameToCheck then
return GetUnitName(unit, showServerName)
end
local customName = lib.Get(nameToCheck)
local realmRelationship = UnitRealmRelationship(unit)
if realmRelationship == LE_REALM_RELATION_SAME or not realmRelationship then
Expand Down

0 comments on commit dcdfd15

Please sign in to comment.