FYI, the lines I've marked in red are unnecessary and do nothing but consume CPU cycles. Since your frame is only registered for those three events, and you want to run the same code in response to all three events, there's no need to check if the event is one of the three; frames only receive events they have registered for.
Code:
f:RegisterEvent("ZONE_CHANGED_NEW_AREA")
f:RegisterEvent("WORLD_MAP_UPDATE")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event)
if event == "ZONE_CHANGED_NEW_AREA" or event == "WORLD_MAP_UPDATE" or event == "PLAYER_ENTERING_WORLD" then
local zone = GetRealZoneText()
if zone and zone ~= "" then
return ZoneChange(zone)
end
end
end)
You're also creating an extra function closure (wastes memory) for no particular reason; since your addon is only running the code inside the ZoneChange function in response to events, you should just put that code directly inside the event handler.