Quantcast
if UnitLevel("player") == MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()] then return end
local addonName, addon = ...
local core = CreateFrame("Frame")

addon.name = addonName:gsub("Broker_", "")

core:RegisterEvent("PLAYER_LOGIN")
core:RegisterEvent("PLAYER_XP_UPDATE")
local function onEvent(self, event, ...)
	if self[event] and type(self[event]) == "function" then
		self[event](self, event, ...)
	end
end
core:SetScript('OnEvent', onEvent)

local class = select(2, UnitClass("player"))
local label = ConvertRGBtoColorString(RAID_CLASS_COLORS[class])  .. "XP|r"

function core:PLAYER_LOGIN()
	addon.dataobj = LibStub("LibDataBroker-1.1"):NewDataObject(addon.name, {
		type = "data source",
		label = label,
		text = addon:GetTitle(),
		OnClick = function(self, button)
			if IsModifierKeyDown() then
				addon:Paste()
			end
		end,
		OnTooltipShow = function(self)
			addon:DisplayTooltip(self)
		end,
	})
end

function core:PLAYER_XP_UPDATE(event, unit)
	if unit == "player" then
		addon.dataobj.text = addon:GetTitle()
	end
end