|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Core\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Core\DataProviders\Listener\MatchDataListenerInterface; |
|
6
|
|
|
use eXpansion\Core\DataProviders\Listener\TimerDataListenerInterface; |
|
7
|
|
|
use eXpansion\Core\Helpers\Time; |
|
8
|
|
|
use eXpansion\Core\Services\Console; |
|
9
|
|
|
use eXpansion\Core\Storage\Data\Player; |
|
10
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
11
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
|
12
|
|
|
|
|
13
|
|
|
class Test implements MatchDataListenerInterface, TimerDataListenerInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var Connection */ |
|
16
|
|
|
protected $connection; |
|
17
|
|
|
/** @var Console */ |
|
18
|
|
|
protected $console; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var int |
|
22
|
|
|
*/ |
|
23
|
|
|
private $time = 0; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var float|int |
|
27
|
|
|
*/ |
|
28
|
|
|
private $previousMemoryValue = 0; |
|
29
|
|
|
|
|
30
|
|
|
function __construct(Connection $connection, Console $console) |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
$this->connection = $connection; |
|
33
|
|
|
$this->console = $console; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function onBeginMatch() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->console->writeln('$0f0Begin Match'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function onEndMatch() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->console->writeln('$0f0End Match'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function onBeginMap(Map $map) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->console->writeln('$0f0Begin Map: $fff' . $map->name); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function onEndMap(Map $map) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->console->writeln('$0f0End Map: $fff' . $map->name); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Callback when player passes checkpoint. |
|
58
|
|
|
* |
|
59
|
|
|
* @param Player $player |
|
60
|
|
|
* @param $time |
|
61
|
|
|
* @param $lap |
|
62
|
|
|
* @param $index |
|
63
|
|
|
* @return mixed |
|
64
|
|
|
*/ |
|
65
|
|
|
public function onPlayerCheckpoint(Player $player, $time, $lap, $index) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->console->writeln('$0f0Checkpoint $ff0' . $index . ': $fff' . Time::TMtoMS($time, true) . ' $777' . $player->getNickName()); |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Callback when player retire or finish |
|
73
|
|
|
* @param Player $player |
|
74
|
|
|
* @param $time 0 if retire, > 0 if finish |
|
75
|
|
|
* @return mixed |
|
76
|
|
|
*/ |
|
77
|
|
|
public function onPlayerFinish(Player $player, $time) |
|
78
|
|
|
{ |
|
79
|
|
|
if ($time > 0) { |
|
80
|
|
|
$this->console->writeln('$777' . $player->getNickName() . ' $0f0Finished with time: $fff' . Time::TMtoMS($time, true)); |
|
81
|
|
|
} else { |
|
82
|
|
|
$this->console->writeln('$777' . $player->getNickName() . ' $f00Retired'); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function onBeginRound() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->console->writeln('$0f0 Begin Round'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function onEndRound() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->console->writeln('$0f0 End Round'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function onPreLoop() |
|
97
|
|
|
{ |
|
98
|
|
|
// TODO: Implement onPreLoop() method. |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function onPostLoop() |
|
102
|
|
|
{ |
|
103
|
|
|
// TODO: Implement onPostLoop() method. |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function onEverySecond() |
|
107
|
|
|
{ |
|
108
|
|
|
$mem = memory_get_usage(true) / 1024; |
|
109
|
|
|
if ($this->previousMemoryValue != $mem) { |
|
110
|
|
|
|
|
111
|
|
|
$diff = ($mem - $this->previousMemoryValue); |
|
112
|
|
|
$msg = '$fff> Memory: $ff0' . $mem . "kb "; |
|
113
|
|
|
|
|
114
|
|
|
if ($this->previousMemoryValue < $mem) { |
|
115
|
|
|
$msg .= ' $f00+' . $diff . "kb"; |
|
116
|
|
|
} else { |
|
117
|
|
|
$msg .= ' $0f0-' . $diff . "kb"; |
|
118
|
|
|
} |
|
119
|
|
|
$this->console->writeln($msg); |
|
120
|
|
|
|
|
121
|
|
|
$this->previousMemoryValue = $mem; |
|
122
|
|
|
|
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.