|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\Maps\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups; |
|
6
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceMpLegacyMap; |
|
7
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceMpLegacyMaplist; |
|
8
|
|
|
use eXpansion\Framework\Core\Helpers\ChatNotification; |
|
9
|
|
|
use eXpansion\Framework\Core\Helpers\TMString; |
|
10
|
|
|
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface; |
|
11
|
|
|
use eXpansion\Framework\Core\Services\Console; |
|
12
|
|
|
use eXpansion\Framework\Core\Storage\MapStorage; |
|
13
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
|
14
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
15
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class Maps implements ListenerInterfaceMpLegacyMap, ListenerInterfaceMpLegacyMaplist, StatusAwarePluginInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var Connection */ |
|
21
|
|
|
protected $connection; |
|
22
|
|
|
|
|
23
|
|
|
/** @var Console */ |
|
24
|
|
|
protected $console; |
|
25
|
|
|
|
|
26
|
|
|
/** @var AdminGroups */ |
|
27
|
|
|
protected $adminGroups; |
|
28
|
|
|
|
|
29
|
|
|
/** @var bool */ |
|
30
|
|
|
protected $enabled = true; |
|
31
|
|
|
|
|
32
|
|
|
/** @var MapStorage */ |
|
33
|
|
|
protected $mapStorage; |
|
34
|
|
|
|
|
35
|
|
|
/** @var ChatNotification */ |
|
36
|
|
|
protected $chatNotification; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var PlayerStorage |
|
39
|
|
|
*/ |
|
40
|
|
|
private $playerStorage; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Maps constructor. |
|
44
|
|
|
* @param Connection $connection |
|
45
|
|
|
* @param Console $console |
|
46
|
|
|
* @param AdminGroups $adminGroups |
|
47
|
|
|
* @param MapStorage $mapStorage |
|
48
|
|
|
* @param ChatNotification $chatNotification |
|
49
|
|
|
* @param PlayerStorage $playerStorage |
|
50
|
|
|
*/ |
|
51
|
|
|
function __construct( |
|
|
|
|
|
|
52
|
|
|
Connection $connection, |
|
53
|
|
|
Console $console, |
|
54
|
|
|
AdminGroups $adminGroups, |
|
55
|
|
|
MapStorage $mapStorage, |
|
56
|
|
|
ChatNotification $chatNotification, |
|
57
|
|
|
PlayerStorage $playerStorage |
|
58
|
|
|
) { |
|
59
|
|
|
$this->connection = $connection; |
|
60
|
|
|
$this->console = $console; |
|
61
|
|
|
$this->adminGroups = $adminGroups; |
|
62
|
|
|
$this->mapStorage = $mapStorage; |
|
63
|
|
|
$this->chatNotification = $chatNotification; |
|
64
|
|
|
$this->playerStorage = $playerStorage; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Set the status of the plugin |
|
69
|
|
|
* |
|
70
|
|
|
* @param boolean $status |
|
71
|
|
|
* |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
public function setStatus($status) |
|
75
|
|
|
{ |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return Map[] |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getMaps() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->mapStorage->getMaps(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
public function removeMap($login, $index) |
|
89
|
|
|
{ |
|
90
|
|
|
if (!$this->adminGroups->hasPermission($login, 'maps')) { |
|
91
|
|
|
$this->chatNotification->sendMessage('expansion_maps.chat.nopermission', $login); |
|
92
|
|
|
} |
|
93
|
|
|
if ($index == "this") { |
|
94
|
|
|
$map = $this->mapStorage->getCurrentMap(); |
|
95
|
|
|
} else { |
|
96
|
|
|
if (is_numeric($index)) { |
|
97
|
|
|
$map = $this->mapStorage->getMapByIndex($index); |
|
98
|
|
|
} else { |
|
99
|
|
|
$this->chatNotification->sendMessage('expansion_maps.chat.nopermission', $login); |
|
100
|
|
|
|
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$group = $this->adminGroups->getLoginUserGroups($login); |
|
106
|
|
|
$level = $this->adminGroups->getGroupLabel($group->getName()); |
|
107
|
|
|
$nickname = $this->playerStorage->getPlayerInfo($login)->getNickName(); |
|
108
|
|
|
try { |
|
109
|
|
|
$this->connection->removeMap($map->fileName); |
|
110
|
|
|
$this->chatNotification->sendMessage('expansion_maps.chat.removemap', null, |
|
111
|
|
|
["%level%" => $level, "%admin%" => $nickname, "%map%" => TMString::trimControls($map->name)]); |
|
112
|
|
|
} catch (\Exception $e) { |
|
113
|
|
|
$this->chatNotification->sendMessage('expansion_maps.chat.dedicatedexception', $group, |
|
114
|
|
|
["%message%" => $e->getMessage()]); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param \Maniaplanet\DedicatedServer\Structures\Map[] $oldMaps |
|
120
|
|
|
* @param string $currentMapUid |
|
121
|
|
|
* @param string $nextMapUid |
|
122
|
|
|
* @param bool $isListModified |
|
123
|
|
|
* @return mixed|void |
|
124
|
|
|
*/ |
|
125
|
|
|
public function onMapListModified($oldMaps, $currentMapUid, $nextMapUid, $isListModified) |
|
126
|
|
|
{ |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param $currentMap |
|
132
|
|
|
* @param $previousMap |
|
133
|
|
|
*/ |
|
134
|
|
|
public function onExpansionMapChange($currentMap, $previousMap) |
|
135
|
|
|
{ |
|
136
|
|
|
// TODO: Implement onExpansionMapChange() method. |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param $nextMap |
|
141
|
|
|
* @param $previousNextMap |
|
142
|
|
|
*/ |
|
143
|
|
|
public function onExpansionNextMapChange($nextMap, $previousNextMap) |
|
144
|
|
|
{ |
|
145
|
|
|
// TODO: Implement onExpansionNextMapChange() method. |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param Map $map |
|
150
|
|
|
* |
|
151
|
|
|
* @return mixed |
|
152
|
|
|
*/ |
|
153
|
|
|
public function onBeginMap(Map $map) |
|
154
|
|
|
{ |
|
155
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @param Map $map |
|
160
|
|
|
* |
|
161
|
|
|
* @return mixed |
|
162
|
|
|
*/ |
|
163
|
|
|
public function onEndMap(Map $map) |
|
164
|
|
|
{ |
|
165
|
|
|
// TODO: Implement onEndMap() method. |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.