|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\WidgetBestCheckpoints\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Bundle\LocalRecords\DataProviders\Listener\RecordsDataListener; |
|
6
|
|
|
use eXpansion\Bundle\LocalRecords\Model\Record; |
|
7
|
|
|
use eXpansion\Bundle\LocalRecords\Plugins\BaseRecords; |
|
8
|
|
|
use eXpansion\Bundle\WidgetBestCheckpoints\Plugins\Gui\BestCheckpointsWidgetFactory; |
|
9
|
|
|
use eXpansion\Bundle\WidgetBestCheckpoints\Plugins\Gui\UpdaterWidgetFactory; |
|
10
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
11
|
|
|
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface; |
|
12
|
|
|
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory; |
|
13
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
|
14
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyMap; |
|
15
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class BestCheckpoints implements StatusAwarePluginInterface, RecordsDataListener, ListenerInterfaceMpLegacyMap |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var PlayerStorage |
|
22
|
|
|
*/ |
|
23
|
|
|
private $playerStorage; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var BestCheckpointsWidgetFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
private $widget; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Group |
|
30
|
|
|
*/ |
|
31
|
|
|
private $players; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var UpdaterWidgetFactory |
|
34
|
|
|
*/ |
|
35
|
|
|
private $updater; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var Group |
|
38
|
|
|
*/ |
|
39
|
|
|
private $allPlayers; |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* BestCheckpoints constructor. |
|
44
|
|
|
* |
|
45
|
|
|
* @param Factory $factory |
|
|
|
|
|
|
46
|
|
|
* @param PlayerStorage $playerStorage |
|
47
|
|
|
* @param BestCheckpointsWidgetFactory $widget |
|
48
|
|
|
* @param UpdaterWidgetFactory $updater |
|
49
|
|
|
* @param Group $players |
|
50
|
|
|
* @param Group $allPlayers |
|
51
|
|
|
*/ |
|
52
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
53
|
|
|
PlayerStorage $playerStorage, |
|
54
|
|
|
BestCheckPointsWidgetFactory $widget, |
|
55
|
|
|
UpdaterWidgetFactory $updater, |
|
56
|
|
|
Group $players, |
|
57
|
|
|
Group $allPlayers |
|
58
|
|
|
) { |
|
59
|
|
|
$this->playerStorage = $playerStorage; |
|
60
|
|
|
$this->widget = $widget; |
|
61
|
|
|
$this->players = $players; |
|
62
|
|
|
$this->updater = $updater; |
|
63
|
|
|
$this->allPlayers = $allPlayers; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Set the status of the plugin |
|
68
|
|
|
* |
|
69
|
|
|
* @param boolean $status |
|
70
|
|
|
* |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setStatus($status) |
|
74
|
|
|
{ |
|
75
|
|
|
if ($status) { |
|
76
|
|
|
$this->widget->create($this->players); |
|
77
|
|
|
$this->updater->create($this->allPlayers); |
|
78
|
|
|
} else { |
|
79
|
|
|
$this->widget->destroy($this->players); |
|
80
|
|
|
$this->updater->destroy($this->allPlayers); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Called when local records are loaded. |
|
86
|
|
|
* |
|
87
|
|
|
* @param Record[] $records |
|
88
|
|
|
*/ |
|
89
|
|
|
public function onLocalRecordsLoaded($records, BaseRecords $baseRecords) |
|
90
|
|
|
{ |
|
91
|
|
|
if (!$this->checkRecordPlugin($baseRecords)) { |
|
92
|
|
|
return; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (count($records) > 0) { |
|
96
|
|
|
$this->updater->setLocalRecord($records[0]->getCheckpoints()); |
|
97
|
|
|
} else { |
|
98
|
|
|
$this->updater->setLocalRecord([]); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Called when a player finishes map for the very first time (basically first record). |
|
104
|
|
|
* |
|
105
|
|
|
* @param Record $record |
|
106
|
|
|
* @param Record[] $records |
|
107
|
|
|
* @param $position |
|
108
|
|
|
*/ |
|
109
|
|
|
public function onLocalRecordsFirstRecord(Record $record, $records, $position, BaseRecords $baseRecords) |
|
110
|
|
|
{ |
|
111
|
|
|
if (!$this->checkRecordPlugin($baseRecords)) { |
|
112
|
|
|
return; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
$this->updater->setLocalRecord($record->getCheckpoints()); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Called when a player finishes map and does same time as before. |
|
120
|
|
|
* |
|
121
|
|
|
* @param Record $record |
|
122
|
|
|
* @param Record $oldRecord |
|
123
|
|
|
* @param Record[] $records |
|
124
|
|
|
*/ |
|
125
|
|
|
public function onLocalRecordsSameScore(Record $record, Record $oldRecord, $records, BaseRecords $baseRecords) |
|
126
|
|
|
{ |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Called when a player finishes map with better time and has better position. |
|
132
|
|
|
* |
|
133
|
|
|
* @param Record $record |
|
134
|
|
|
* @param Record $oldRecord |
|
135
|
|
|
* @param Record[] $records |
|
136
|
|
|
* @param int $position |
|
137
|
|
|
* @param int $oldPosition |
|
138
|
|
|
*/ |
|
139
|
|
View Code Duplication |
public function onLocalRecordsBetterPosition(Record $record, Record $oldRecord, $records, $position, $oldPosition, BaseRecords $baseRecords) |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
|
|
if (!$this->checkRecordPlugin($baseRecords)) { |
|
142
|
|
|
return; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
if ($position == 1) { |
|
146
|
|
|
$this->updater->setLocalRecord($record->getCheckpoints()); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Called when a player finishes map with better time but keeps same position. |
|
152
|
|
|
* |
|
153
|
|
|
* @param Record $record |
|
154
|
|
|
* @param Record $oldRecord |
|
155
|
|
|
* @param Record[] $records |
|
156
|
|
|
* @param $position |
|
157
|
|
|
*/ |
|
158
|
|
View Code Duplication |
public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position, BaseRecords $baseRecords) |
|
|
|
|
|
|
159
|
|
|
{ |
|
160
|
|
|
if (!$this->checkRecordPlugin($baseRecords)) { |
|
161
|
|
|
return; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
if ($position == 1) { |
|
165
|
|
|
$this->updater->setLocalRecord($record->getCheckpoints()); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Check if we can use the data for this plugin. |
|
171
|
|
|
* |
|
172
|
|
|
* @param BaseRecords $baseRecords |
|
173
|
|
|
* |
|
174
|
|
|
* @return bool |
|
175
|
|
|
*/ |
|
176
|
|
|
protected function checkRecordPlugin(BaseRecords $baseRecords) |
|
177
|
|
|
{ |
|
178
|
|
|
return $baseRecords->getRecordsHandler()->getCurrentNbLaps() == 1; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param Map $map |
|
183
|
|
|
* |
|
184
|
|
|
* @return void |
|
185
|
|
|
*/ |
|
186
|
|
|
public function onBeginMap(Map $map) |
|
187
|
|
|
{ |
|
188
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param Map $map |
|
193
|
|
|
* |
|
194
|
|
|
* @return void |
|
195
|
|
|
*/ |
|
196
|
|
|
public function onEndMap(Map $map) |
|
197
|
|
|
{ |
|
198
|
|
|
$this->updater->setLocalRecord([]); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.