
Open Raid is a library to share the player information while playing in a group or raid.

Install:
Place the library at your addon folder/libs/LibOpenRaid/
Inside LibOpenRaid there's 5 files.
Add <Include file="Libs\LibOpenRaid\lib.xml"/> to your libs.xml located in the root folder of the addon or 
<Include file="LibOpenRaid\lib.xml"/> if it is located inside the Libs folder.
Close and open the game client.

Inside your lua file, get the library object, you need to do this in order to grab a reference of the library:
local openRaidLib = LibStub:GetLibrary("LibOpenRaid-1.0")
With this object, you can start querying the library for information.

Functions:

local sentRequest = openRaidLib.RequestAllPlayersInfo()
Request to all players to send all data infomation: cooldowns, gear and player data.
Instants after calling this, expect to receive several callbacks.


local allPlayersGear = openRaidLib.gearManager.GetAllPlayersGear()
allPlayersGear = {
    ["playerName1"] = playerGear,
    ["playerName2"] = playerGear,
    ["playerName3"] = playerGear,
}

local playerGear = openRaidLib.gearManager.GetPlayerGear(playerName)
playerGear = {
    .durability = number
    .ilevel = number
    .noGems = {socketId}
    .noEnchants = {socketId}
    .weaponEnchant = number (oils)
}


local allPlayersCooldowns = openRaidLib.cooldownManager.GetAllPlayersCooldown()
allPlayersCooldowns = {
    ["playerName1"] = playerCooldows,
    ["playerName2"] = playerCooldows,
    ["playerName3"] = playerCooldows,
}

local playerCooldows = openRaidLib.cooldownManager.GetPlayerCooldowns(playerName)
playerCooldows = {
    [cooldownSpellId] = {
        [1] = time left (number), 
        [2] = charges (number),
        [3] = start time (number),
        [4] = duration (number)
    }
}


local allPlayersInfo = openRaidLib.playerInfoManager.GetAllPlayersInfo()
allPlayersInfo = {
    ["playerName1"] = playerInfo,
    ["playerName2"] = playerInfo,
    ["playerName3"] = playerInfo,
}

local playerInfo = openRaidLib.playerInfoManager.GetPlayerInfo(playerName)
playerInfo = {
    .specId = number
    .renown = number, 
    .covenantId = number,
    .talents = {talentId}, 
    .conduits = {spellId},
}

Callbacks:

===================================================================================================================================
"CooldownListUpdate": triggers when the lib received a list of cooldowns from another player in the group.
===================================================================================================================================

function MyAddonObject.OnReceiveCooldownListUpdate(unitName, playerCooldows, allPlayersCooldowns)
    --foreach player in the cooldown table
    for unitName, playerCooldows in pairs(allPlayersCooldowns) do
        for spellId, cooldownInfoTable in pairs(playerCooldows) do
            --time left for the cooldown be ready to use, if time left is zero, the spell is ready
            local timeLeft = cooldownInfoTable[1]
            --in some cases the spell is on cooldown but there's a charge to use
            local charges = cooldownInfoTable[2]
            --cooldown start time
            local startTime = cooldownInfoTable[3]
            --cooldown duration, e.g. 180 for 3 minutes cooldown
            local totalDuration = cooldownInfoTable[4]
        end
    end

    --get the cooldowns for the unit which got the cooldown update
    local playerCooldows = allPlayersCooldowns[unitName]
    for spellId, cooldownInfoTable in pairs(playerCooldows) do
            --time left for the cooldown be ready to use, if time left is zero, the spell is ready
            local timeLeft = cooldownInfoTable[1]
            --in some cases the spell is on cooldown but there's a charge to use
            local charges = cooldownInfoTable[2]
            --cooldown start time
            local startTime = cooldownInfoTable[3]
            --cooldown duration, e.g. 180 for 3 minutes cooldown
            local totalDuration = cooldownInfoTable[4]
    end
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "CooldownListUpdate", "OnReceiveCooldownListUpdate")

===================================================================================================================================
"CooldownUpdate": triggered when any unit in the group used a cooldown or the timeleft got an update
===================================================================================================================================

function MyAddonObject.OnReceiveCooldownUpdate(unitName, spellId, cooldownTimeLeft, charges, startTime, totalDuration, playerCooldows, allPlayersCooldowns)
    local unitCooldowns = allPlayersCooldowns[unitName] --is the same as using just 'playerCooldows' variable

    --get the cooldowns for the unit which got the cooldown update
    for spellId, cooldownInfoTable in pairs(playerCooldows) do
            --time left for the cooldown be ready to use, if time left is zero, the spell is ready
            local timeLeft = cooldownInfoTable[1]
            --in some cases the spell is on cooldown but there's a charge to use
            local charges = cooldownInfoTable[2]
            --cooldown start time
            local startTime = cooldownInfoTable[3]
            --cooldown duration, e.g. 180 for 3 minutes cooldown
            local totalDuration = cooldownInfoTable[4]
    end
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "CooldownUpdate", "OnReceiveCooldownUpdate")

===================================================================================================================================
"CooldownListWiped": when the list of cooldowns get a wipe, usually when the player leave the group
===================================================================================================================================

function MyAddonObject.OnCooldownListWipe(allPlayersCooldowns)
    --print ("is nil:", next(allPlayersCooldowns))
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "CooldownListWiped", "OnCooldownListWipe")


===================================================================================================================================
"GearUpdate": when received an update from a player with all information about the gear
===================================================================================================================================

function MyAddonObject.OnGearUpdate(playerName, playerGear, allPlayersGear)
    local itemLevelNumber = playerGear.ilevel
    local durabilityNumber = playerGear.durability
    --hasWeaponEnchant is 1 have enchant or 0 is don't
    local hasWeaponEnchantNumber = playerGear.weaponEnchant
    local noEnchantTable = playerGear.noEnchants
    local noGemsTable = playerGear.noGems

    for index, slotIdWithoutEnchant in ipairs (noEnchantTable) do
    end

    for index, slotIdWithEmptyGemSocket in ipairs (noGemsTable) do
    end
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "GearUpdate", "OnGearUpdate")

===================================================================================================================================
"GearDurabilityUpdate": when the gear durability of a player in the group changes
===================================================================================================================================

function MyAddonObject.OnGearDurabilityUpdate(playerName, durability, playerGear, allPlayersGear)
    --print(playerName .. " durability is now " .. durability)
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "GearDurabilityUpdate", "OnGearDurabilityUpdate")

===================================================================================================================================
"GearListWiped": when the list of gear get a wipe, usually when the player leave the group
===================================================================================================================================

function MyAddonObject.OnGearListWiped(allPlayersGear)
    --print ("is nil:", next(allPlayersGear))
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "GearListWiped", "OnGearListWiped")

===================================================================================================================================
"PlayerUpdate": received a player information about its spec, talents, etc...
===================================================================================================================================

function MyAddonObject.OnPlayerUpdate(playerName, playerInfo, allPlayersInfo)
    for unitName, playerInfo in pairs(allPlayersInfo) do
        local specId = playerInfo.specId
        local renown = playerInfo.renown
        local covenantId = playerInfo.covenantId
        local talents = playerInfo.talents 
        local conduits = playerInfo.conduits
    end
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "PlayerUpdate", "OnPlayerUpdate")

===================================================================================================================================
"TalentsUpdate": when a unit changed a talent
===================================================================================================================================

function MyAddonObject.OnTalentUpdate(playerName, talents, playerInfo, allPlayersInfo)
    for i = 1, 7 do
        local talentId = talents[i]
        local talentID, name, texture, selected, available = GetTalentInfoByID(talentId)
        print(name)
    end
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "TalentUpdate", "OnTalentUpdate")


===================================================================================================================================
"OnPlayerDeath": when a player dies
===================================================================================================================================

function MyAddonObject.OnPlayerDeath(playerName)
    print(playerName .. " died.")
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "OnPlayerDeath", "OnPlayerDeath")

===================================================================================================================================
"OnPlayerRess": when a player revives
===================================================================================================================================

function MyAddonObject.OnPlayerRess(playerName)
    print(playerName .. " is alive.")
end

--registering the callback:
openRaidLib.RegisterCallback(MyAddonObject, "OnPlayerRess", "OnPlayerRess")

