|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Config\Model\TextConfig; |
|
6
|
|
|
use eXpansion\Framework\Core\Helpers\FileSystem; |
|
7
|
|
|
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory; |
|
8
|
|
|
use eXpansion\Framework\Core\Storage\GameDataStorage; |
|
9
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyMap; |
|
10
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
|
11
|
|
|
use Psr\Log\LoggerInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class AutomaticServerSettingsSave |
|
15
|
|
|
* |
|
16
|
|
|
* @author de Cramer Oliver<[email protected]> |
|
17
|
|
|
* @copyright 2018 Oliverde8 |
|
18
|
|
|
* @package eXpansion\Framework\Core\Plugins |
|
19
|
|
|
*/ |
|
20
|
|
|
class AutomaticMatchSettingsSave implements ListenerInterfaceMpLegacyMap, StatusAwarePluginInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var FileSystem */ |
|
23
|
|
|
protected $fileSystem; |
|
24
|
|
|
|
|
25
|
|
|
/** @var Factory */ |
|
26
|
|
|
protected $connectionFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** @var LoggerInterface */ |
|
29
|
|
|
protected $logger; |
|
30
|
|
|
|
|
31
|
|
|
/** @var TextConfig */ |
|
32
|
|
|
protected $fileName; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* AutomaticServerSettingsSave constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param FileSystem $fileSystem |
|
38
|
|
|
* @param Factory $connectionFactory |
|
39
|
|
|
* @param LoggerInterface $logger |
|
40
|
|
|
* @param TextConfig $fileName |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(FileSystem $fileSystem, Factory $connectionFactory, LoggerInterface $logger, TextConfig $fileName) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->fileSystem = $fileSystem; |
|
45
|
|
|
$this->connectionFactory = $connectionFactory; |
|
46
|
|
|
$this->logger = $logger; |
|
47
|
|
|
$this->fileName = $fileName; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
public function saveFile() |
|
52
|
|
|
{ |
|
53
|
|
|
if (!$this->fileName->get()) { |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$path = 'MatchSettings/' . $this->fileName->get(); |
|
58
|
|
|
|
|
59
|
|
|
try { |
|
60
|
|
|
$this->connectionFactory->getConnection()->saveMatchSettings($path); |
|
61
|
|
|
} catch (\Exception $e) { |
|
62
|
|
|
$this->logger->error('Failed to save match settings!', ['exception' => $e]); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param Map $map |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
public function onBeginMap(Map $map) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->saveFile(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param Map $map |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
|
public function onEndMap(Map $map) |
|
82
|
|
|
{ |
|
83
|
|
|
// Nothing to do. |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Set the status of the plugin |
|
88
|
|
|
* |
|
89
|
|
|
* @param boolean $status |
|
90
|
|
|
* |
|
91
|
|
|
* @return null |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setStatus($status) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->saveFile(); |
|
96
|
|
|
} |
|
97
|
|
|
} |