|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\ImmersiveWindows\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Model\Gui\Manialink; |
|
6
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyPlayer; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkFactoryInterface; |
|
8
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
9
|
|
|
use eXpansion\Framework\Core\Model\Gui\Window; |
|
10
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
11
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\ManialinkFactory; |
|
12
|
|
|
use eXpansion\Framework\Core\Plugins\GuiHandler; |
|
13
|
|
|
use eXpansion\Framework\Core\Plugins\GuiHandlerInterface; |
|
14
|
|
|
use eXpansion\Framework\Core\Services\Console; |
|
15
|
|
|
use eXpansion\Framework\Core\Storage\Data\Player; |
|
16
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
17
|
|
|
use Psr\Log\LoggerInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class WindowsGuiHandler, replaces the native GuiHandler only for windows type manialinks in order to : |
|
21
|
|
|
* - Prevent more then 1 window to open. |
|
22
|
|
|
* - Change the display |
|
23
|
|
|
* |
|
24
|
|
|
* |
|
25
|
|
|
* @author de Cramer Oliver<[email protected]> |
|
26
|
|
|
* @copyright 2017 eXpansion |
|
27
|
|
|
* @package eXpansion\Bundle\Menu\Plugins |
|
28
|
|
|
*/ |
|
29
|
|
|
class WindowsGuiHandler implements GuiHandlerInterface, ListenerInterfaceMpLegacyPlayer |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
/** @var Window[] */ |
|
33
|
|
|
protected $userWindows = []; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var GuiHandler |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $guiHandler; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* WindowsGuiHandler constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param GuiHandler $guiHandler |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct(GuiHandler $guiHandler) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->guiHandler = $guiHandler; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @inheritdoc |
|
52
|
|
|
*/ |
|
53
|
|
|
public function addToDisplay(ManialinkInterface $manialink) |
|
54
|
|
|
{ |
|
55
|
|
|
$logins = $manialink->getUserGroup()->getLogins(); |
|
56
|
|
|
|
|
57
|
|
|
if (count($logins) == 1 && !$manialink->getUserGroup()->isPersistent()) { |
|
58
|
|
|
$login = $logins[0]; |
|
59
|
|
|
|
|
60
|
|
|
// If a window is already displayed hide it. We wish to have 1 window max. |
|
61
|
|
|
if (isset($this->userWindows[$login]) && $this->userWindows[$login]->getId() != $manialink->getId()) { |
|
62
|
|
|
$this->guiHandler->addToHide($this->userWindows[$login]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$this->userWindows[$login] = $manialink; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->guiHandler->addToDisplay($manialink); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @inheritdoc |
|
73
|
|
|
*/ |
|
74
|
|
|
public function addToHide(ManialinkInterface $manialink) |
|
75
|
|
|
{ |
|
76
|
|
|
$logins = $manialink->getUserGroup()->getLogins(); |
|
77
|
|
|
if (count($logins) == 1 && !$manialink->getUserGroup()->isPersistent()) { |
|
78
|
|
|
$login = $logins[0]; |
|
79
|
|
|
|
|
80
|
|
|
if (isset($this->userWindows[$login])) { |
|
81
|
|
|
unset($this->userWindows[$login]); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$this->guiHandler->addToHide($manialink); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @inheritdoc |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getManialink(Group $group, ManialinkFactoryInterface $manialinkFactory) |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->guiHandler->getManialink($group, $manialinkFactory); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @inheritdoc |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getFactoryManialinks(ManialinkFactory $manialinkFactory) |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->guiHandler->getFactoryManialinks($manialinkFactory); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @inheritdoc |
|
107
|
|
|
*/ |
|
108
|
|
|
public function onPlayerConnect(Player $player) |
|
109
|
|
|
{ |
|
110
|
|
|
// Nothing |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @inheritdoc |
|
115
|
|
|
*/ |
|
116
|
|
|
public function onPlayerDisconnect(Player $player, $disconnectionReason) |
|
117
|
|
|
{ |
|
118
|
|
|
if (isset($this->userWindows[$player->getLogin()])) { |
|
119
|
|
|
unset($this->userWindows[$player->getLogin()]); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @inheritdoc |
|
125
|
|
|
*/ |
|
126
|
|
|
public function onPlayerInfoChanged(Player $oldPlayer, Player $player) |
|
127
|
|
|
{ |
|
128
|
|
|
// Nothing |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @inheritdoc |
|
133
|
|
|
*/ |
|
134
|
|
|
public function onPlayerAlliesChanged(Player $oldPlayer, Player $player) |
|
135
|
|
|
{ |
|
136
|
|
|
// Nothing |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|