/**
  * Erstellt eine Allianz mit dem Avatar als Leader
  * @param \DragonJsonServerAvatar\Entity\Avatar $avatar
  * @param string $tag
  * @param string $name
  * @return \DragonJsonServerAlliance\Entity\Alliance
  */
 public function createAlliance(\DragonJsonServerAvatar\Entity\Avatar $avatar, $tag, $name)
 {
     $alliance = (new \DragonJsonServerAlliance\Entity\Alliance())->setGameroundId($avatar->getGameroundId())->setTag($tag)->setName($name);
     $this->getServiceManager()->get('\\DragonJsonServerDoctrine\\Service\\Doctrine')->transactional(function ($entityManager) use($avatar, $alliance) {
         $entityManager->persist($alliance);
         $entityManager->flush();
         $allianceavatar = $this->getServiceManager()->get('\\DragonJsonServerAlliance\\Service\\Allianceavatar')->createAllianceavatar($avatar, $alliance, 'leader');
         $this->getEventManager()->trigger((new \DragonJsonServerAlliance\Event\CreateAlliance())->setTarget($this)->setAlliance($alliance)->setAllianceavatar($allianceavatar));
     });
     return $alliance;
 }
 /**
  * Erstellt einen Avatarmutebann für den Avatar
  * @param \DragonJsonServerAvatar\Entity\Avatar $avatar
  * @param \DateTime $end
  * @return \DragonJsonServerAvatarmuteban\Entity\Avatarmuteban
  */
 public function createAvatarmuteban(\DragonJsonServerAvatar\Entity\Avatar $avatar, \DateTime $end)
 {
     $avatar_id = $avatar->getAvatarId();
     $avatarmuteban = $this->getAvatarmutebanByAvatarId($avatar_id, false);
     if (null === $avatarmuteban) {
         $avatarmuteban = (new \DragonJsonServerAvatarmuteban\Entity\Avatarmuteban())->setAvatarId($avatar_id)->setEnd($end);
     } else {
         $avatarmuteban->setEnd($end);
     }
     $this->getServiceManager()->get('\\DragonJsonServerDoctrine\\Service\\Doctrine')->transactional(function ($entityManager) use($avatarmuteban) {
         $entityManager->persist($avatarmuteban);
         $entityManager->flush();
         $this->getEventManager()->trigger((new \DragonJsonServerAvatarmuteban\Event\CreateAvatarmuteban())->setTarget($this)->setAvatarmuteban($avatarmuteban));
     });
     return $avatarmuteban;
 }
 /**
  * Gibt die Allianzbeziehung mit der übergebenen AvatarID zurück
  * @param \DragonJsonServerAvatar\Entity\Avatar $avatar
  * @param boolean $throwException
  * @return \DragonJsonServerAlliance\Entity\Allianceavatar|null
  * @throws \DragonJsonServer\Exception
  */
 public function getAllianceavatarByAvatar($avatar, $throwException = true)
 {
     $entityManager = $this->getEntityManager();
     $allianceavatar = $entityManager->getRepository('\\DragonJsonServerAlliance\\Entity\\Allianceavatar')->findOneBy(['avatar' => $avatar]);
     if (null === $allianceavatar && $throwException) {
         throw new \DragonJsonServer\Exception('invalid avatar', ['avatar' => $avatar->toArray()]);
     }
     return $allianceavatar;
 }
 /**
  * Gibt die Avatarnachrichten für den Avatar und die Clientmessages zurück
  * @param \DragonJsonServerAvatar\Entity\Avatar $avatar
  * @param \DragonJsonServer\Event\Clientmessages $eventClientmessages
  * @return array
  */
 public function getAvatarmessagesByEventClientmessages(\DragonJsonServerAvatar\Entity\Avatar $avatar, \DragonJsonServer\Event\Clientmessages $eventClientmessages)
 {
     $entityManager = $this->getEntityManager();
     return $entityManager->createQuery("\n\t\t\t\tSELECT avatarmessage FROM \\DragonJsonServerAvatarmessage\\Entity\\Avatarmessage avatarmessage\n\t\t\t\tWHERE\n\t\t\t\t\tavatarmessage.to_avatar = :to_avatar_id\n\t\t\t\t\tAND\n\t\t\t\t\tavatarmessage.to_state = 'new'\n\t\t\t\t\tAND\n\t\t\t\t\tavatarmessage.created >= :from AND avatarmessage.created < :to \n\t\t\t")->execute(['to_avatar_id' => $avatar->getAvatarId(), 'from' => $eventClientmessages->getFrom(), 'to' => $eventClientmessages->getTo()]);
 }