bool ToLegionHold(uint32 i, AuraPointer pAura, bool apply)
{
	if ( pAura == NULL || pAura->GetUnitCaster() == NULL || !pAura->GetUnitCaster()->IsPlayer() )
		return true;

	PlayerPointer pPlayer = TO_PLAYER( pAura->GetUnitCaster() );

	CreaturePointer pJovaanCheck = pPlayer->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(-3310.743896f, 2951.929199f, 171.132538f, 21633);
	if ( pJovaanCheck != NULL )
		return true;

	QuestLogEntry *pQuest = pPlayer->GetQuestLogForEntry( 10563 );
	if ( pQuest == NULL )
	{
		pQuest = pPlayer->GetQuestLogForEntry( 10596 );
		if ( pQuest == NULL )
			return true;
	}

	if ( apply )
	{

		pPlayer->SetUInt32Value( UNIT_FIELD_DISPLAYID, 20366 );
		pPlayer->Root();
		CreaturePointer pJovaan = sEAS.SpawnCreature( pPlayer, 21633, -3310.743896f, 2951.929199f, 171.132538f, 5.054039f, 0 );	// Spawn Jovaan
		if ( pJovaan != NULL )
		{
			pJovaan->SetUInt64Value( UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_ATTACKABLE_2 );
			if ( pJovaan->GetAIInterface() != NULL )
			{
				pJovaan->GetAIInterface()->SetAllowedToEnterCombat( false );
			}
		}
		GameObjectPointer pGameObject = pPlayer->GetMapMgr()->GetInterface()->GetGameObjectNearestCoords(pPlayer->GetPositionX(), pPlayer->GetPositionY(), pPlayer->GetPositionZ(), 184834);
		if ( pGameObject != NULL )
		{
			pGameObject->Despawn(60000);
			pPlayer->UpdateNearbyGameObjects();
		}
	}
	else
	{
		if ( pQuest->GetMobCount( 2 ) < pQuest->GetQuest()->required_mobcount[2] )
		{
			pQuest->SetMobCount( 2, pQuest->GetMobCount( 2 ) + 1 );
			pQuest->SendUpdateAddKill( 2 );
			pQuest->UpdatePlayerFields();
		}
	
		pPlayer->SetUInt32Value( UNIT_FIELD_DISPLAYID, pPlayer->GetUInt32Value( UNIT_FIELD_NATIVEDISPLAYID ) );
		pPlayer->UnRoot();
	}

	return true;
}
void Arena::Finish()
{
	m_ended = true;
	ArenaTeam * teams[2] = {NULL, NULL};
	if(rated_match)
	{
		teams[0] = objmgr.GetArenaTeamById(m_teams[0]);
		teams[1] = objmgr.GetArenaTeamById(m_teams[1]);
	}
	/* update arena team stats */
	if(rated_match && teams[0] && teams[1])
	{
		for (uint32 i = 0; i < 2; ++i) {
			uint32 j = i ? 0 : 1; // opposing side
			bool outcome = (i != m_losingteam);
			if (outcome) {
				teams[i]->m_stat_gameswonseason++;
				teams[i]->m_stat_gameswonweek++;
			}

			m_deltaRating[i] = CalcDeltaRating(teams[i]->m_stat_rating, teams[j]->m_stat_rating, outcome);
			teams[i]->m_stat_rating += m_deltaRating[i];
			if ((int32)teams[i]->m_stat_rating < 0) teams[i]->m_stat_rating = 0;

			for (int x=0; x<hashmap_length(m_players2[i]); x++) {
				uint32 key;
				if (MAP_OK == hashmap_get_index(m_players2[i], x, (int*)&key, (any_t*) NULL)) {
					PlayerInfo * info = objmgr.GetPlayerInfo(key);
					if (info) {
						ArenaTeamMember * tp = teams[i]->GetMember(info);

						if(tp != NULL) {
							tp->PersonalRating += CalcDeltaRating(tp->PersonalRating, teams[j]->m_stat_rating, outcome);
							if ((int32)tp->PersonalRating < 0) tp->PersonalRating = 0;

							if(outcome) {
								tp->Won_ThisWeek++;
								tp->Won_ThisSeason++;
							}
						}
					}
				}
			}
			
			teams[i]->SaveToDB();
			// send arena team stats update
			WorldPacket data(256);
			teams[i]->Stat(data);
			teams[i]->SendPacket(&data);
		}
		objmgr.UpdateArenaTeamRankings();
	}

	m_nextPvPUpdateTime = 0;
	UpdatePvPData();
	PlaySoundToAll(m_losingteam ? SOUND_ALLIANCEWINS : SOUND_HORDEWINS);

	sEventMgr.RemoveEvents(shared_from_this(), EVENT_BATTLEGROUND_CLOSE);
	sEventMgr.RemoveEvents(shared_from_this(), EVENT_ARENA_SHADOW_SIGHT);
	sEventMgr.AddEvent(TO_CBATTLEGROUND(shared_from_this()), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0);

	for(int i = 0; i < 2; i++)
	{
		bool victorious = (i != m_losingteam);
		set<PlayerPointer  >::iterator itr = m_players[i].begin();
		for(; itr != m_players[i].end(); itr++)
		{
			PlayerPointer plr = (PlayerPointer )(*itr);
			plr->Root();

			if( plr->m_bgScore.DamageDone == 0 && plr->m_bgScore.HealingDone == 0 )
				continue;

			sHookInterface.OnArenaFinish(plr, m_arenateamtype, plr->m_playerInfo->arenaTeam[m_arenateamtype], victorious, rated_match);
		}
	}
}