<commit_before><?php

namespace eXpansion\Framework\Core\Plugins\Gui;

use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpUserGroup;
use eXpansion\Framework\Core\Model\Gui\Manialink;
use eXpansion\Framework\Core\Model\Gui\ManialinkFactoryInterface;
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
use eXpansion\Framework\Core\Model\UserGroups\Group;
use eXpansion\Framework\Core\Plugins\GuiHandler;
use eXpansion\Framework\Core\Plugins\UserGroups\Factory;

/**
 * Class ManialiveFactory allow the creation of manialinks.
 *
 * @package eXpansion\Framework\Core\Plugins\Gui
 * @author <NAME>
 */
class ManialinkFactory implements ManialinkFactoryInterface, ListenerInterfaceExpUserGroup
{
    /** @var  GuiHandler */
    protected $guiHandler;

    /** @var Factory  */
    protected $groupFactory;

    /** @var ActionFactory */
    protected $actionFactory;

    /** @var  string */
    protected $name;

    /** @var  string */
    protected $className;

    /** @var ManialinkInterface[]  */
    protected $manialinks = [];

    /** @var Group[] */
    protected $groups = [];

    /** @var float|int */
    protected $sizeX;

    /** @var float|int */
    protected $sizeY;

    /** @var float|int */
    protected $posX;

    /** @var float|int */
    protected $posY;

    /**
     * GroupManialinkFactory constructor.
     *
     * @param GuiHandler $guiHandler
     * @param Factory $groupFactory
     * @param ActionFactory $actionFactory
     * @param $name
     * @param $sizeX
     * @param $sizeY
     * @param null $posX
     * @param null $posY
     * @param string $className
     */
    public function __construct(
        $name,
        $sizeX,
        $sizeY,
        $posX = null,
        $posY = null,
        GuiHandler $guiHandler,
        Factory $groupFactory,
        ActionFactory $actionFactory,
        $className = Manialink::class
    ) {
        if (is_null($posX)) {
            $posX = $sizeX / -2;
        }

        if (is_null($posY)) {
            $posY = $sizeY / 2;
        }

        $this->guiHandler = $guiHandler;
        $this->groupFactory = $groupFactory;
        $this->actionFactory = $actionFactory;
        $this->name = $name;
        $this->className = $className;
        $this->sizeX = $sizeX;
        $this->sizeY = $sizeY;
        $this->posX = $posX;
        $this->posY = $posY;
    }

    /**
     * @inheritdoc
     */
    final public function create($group)
    {
        if (is_string($group)) {
            $group = $this->groupFactory->createForPlayer($group);
        } else if (is_array($group)) {
            $group = $this->groupFactory->createForPlayers($group);
        }

        $this->manialinks[$group->getName()] = $this->createManialink($group);
        $this->guiHandler->addToDisplay($this->manialinks[$group->getName()]);

        $this->createContent($this->manialinks[$group->getName()]);
        $this->updateContent($this->manialinks[$group->getName()]);

        return $group;
    }

    /**
     * @inheritdoc
     * @param Group $group
     */
    final public function update($group)
    {
        if (isset($this->manialinks[$group->getName()])) {
            $this->guiHandler->addToDisplay($this->manialinks[$group->getName()]);
            $this->updateContent($this->manialinks[$group->getName()]);
        }
    }

    /**<commit_msg>#71 - Fixed issue with windows displayed multiple times.<commit_after><?php

namespace eXpansion\Framework\Core\Plugins\Gui;

use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpUserGroup;
use eXpansion\Framework\Core\Model\Gui\Manialink;
use eXpansion\Framework\Core\Model\Gui\ManialinkFactoryInterface;
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
use eXpansion\Framework\Core\Model\UserGroups\Group;
use eXpansion\Framework\Core\Plugins\GuiHandler;
use eXpansion\Framework\Core\Plugins\UserGroups\Factory;

/**
 * Class ManialiveFactory allow the creation of manialinks.
 *
 * @package eXpansion\Framework\Core\Plugins\Gui
 * @author <NAME>
 */
class ManialinkFactory implements ManialinkFactoryInterface, ListenerInterfaceExpUserGroup
{
    /** @var  GuiHandler */
    protected $guiHandler;

    /** @var Factory  */
    protected $groupFactory;

    /** @var ActionFactory */
    protected $actionFactory;

    /** @var  string */
    protected $name;

    /** @var  string */
    protected $className;

    /** @var ManialinkInterface[]  */
    protected $manialinks = [];

    /** @var Group[] */
    protected $groups = [];

    /** @var float|int */
    protected $sizeX;

    /** @var float|int */
    protected $sizeY;

    /** @var float|int */
    protected $posX;

    /** @var float|int */
    protected $posY;

    /**
     * GroupManialinkFactory constructor.
     *
     * @param GuiHandler $guiHandler
     * @param Factory $groupFactory
     * @param ActionFactory $actionFactory
     * @param $name
     * @param $sizeX
     * @param $sizeY
     * @param null $posX
     * @param null $posY
     * @param string $className
     */
    public function __construct(
        $name,
        $sizeX,
        $sizeY,
        $posX = null,
        $posY = null,
        GuiHandler $guiHandler,
        Factory $groupFactory,
        ActionFactory $actionFactory,
        $className = Manialink::class
    ) {
        if (is_null($posX)) {
            $posX = $sizeX / -2;
        }

        if (is_null($posY)) {
            $posY = $sizeY / 2;
        }

        $this->guiHandler = $guiHandler;
        $this->groupFactory = $groupFactory;
        $this->actionFactory = $actionFactory;
        $this->name = $name;
        $this->className = $className;
        $this->sizeX = $sizeX;
        $this->sizeY = $sizeY;
        $this->posX = $posX;
        $this->posY = $posY;
    }

    /**
     * @inheritdoc
     */
    final public function create($group)
    {
        if (is_string($group)) {
            $group = $this->groupFactory->createForPlayer($group);
        } else if (is_array($group)) {
            $group = $this->groupFactory->createForPlayers($group);
        }

        if (isset($this->manialinks[$group->getName()])) {
            $this->update($group);
            return $group;
        }

        $this->manialinks[$group->getName()] = $this->createManialink($group);
        $this->guiHandler->addToDisplay($this->manialinks[$group->getName()]);

        $this->createContent($this->manialinks[$group->getName()]);
        $this->updateContent($this->manialinks[$group->getName()]);

        return $group;
    }

    /**
     * @inheritdoc
     * @param Group $group
     */
    final public function update($group)
    {
        if (isset($this->manialinks[$group->getName()])) {
            $this->guiHandler->addToDisplay($this->manialinks[$group->getName()]);
            $this->updateContent($this->manialinks[$group->getName()]);
        }
    }

    /**
{'fraction_non_alphanumeric': 0.1486741052021446, 'fraction_numerical': 0.000869439211708448, 'mean_word_length': 2.451, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5215937', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2093, 'n_words': 376}