|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\Acme\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\MatchDataListenerInterface; |
|
6
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\TimerDataListenerInterface; |
|
7
|
|
|
use eXpansion\Framework\Core\Helpers\Time; |
|
8
|
|
|
use eXpansion\Framework\Core\Services\Console; |
|
9
|
|
|
use eXpansion\Framework\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
|
|
|
|
|
18
|
|
|
/** @var Console */ |
|
19
|
|
|
protected $console; |
|
20
|
|
|
|
|
21
|
|
|
/** @var Time */ |
|
22
|
|
|
protected $time; |
|
23
|
|
|
|
|
24
|
|
|
/** @var float|int */ |
|
25
|
|
|
private $previousMemoryValue = 0; |
|
26
|
|
|
|
|
27
|
|
|
function __construct(Connection $connection, Console $console, Time $time) |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$this->connection = $connection; |
|
30
|
|
|
$this->console = $console; |
|
31
|
|
|
$this->time = $time; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function onBeginMap(Map $map) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->console->writeln('$0f0Begin Map: $fff'.$map->name); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function onEndMap(Map $map) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->console->writeln('$0f0End Map: $fff'.$map->name); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function onPreLoop() |
|
45
|
|
|
{ |
|
46
|
|
|
// do nothing |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function onPostLoop() |
|
50
|
|
|
{ |
|
51
|
|
|
// do nothing |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function onEverySecond() |
|
55
|
|
|
{ |
|
56
|
|
|
$mem = memory_get_usage(true) / 1024; |
|
57
|
|
|
if ($this->previousMemoryValue != $mem) { |
|
58
|
|
|
|
|
59
|
|
|
$diff = ($mem - $this->previousMemoryValue); |
|
60
|
|
|
$msg = '$fff> Memory: $ff0'.$mem."kb "; |
|
61
|
|
|
|
|
62
|
|
|
if ($this->previousMemoryValue < $mem) { |
|
63
|
|
|
$msg .= ' $f00+'.$diff."kb"; |
|
64
|
|
|
} else { |
|
65
|
|
|
$msg .= ' $0f0-'.$diff."kb"; |
|
66
|
|
|
} |
|
67
|
|
|
$this->console->writeln($msg); |
|
68
|
|
|
|
|
69
|
|
|
$this->previousMemoryValue = $mem; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
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.