|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Core\DataProviders; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Core\Model\Helpers\ChatNotificationInterface; |
|
6
|
|
|
use eXpansion\Core\Services\ChatCommands; |
|
7
|
|
|
|
|
8
|
|
|
class ChatCommandDataProvider extends AbstractDataProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var ChatCommands */ |
|
11
|
|
|
protected $chatCommands; |
|
12
|
|
|
|
|
13
|
|
|
/** @var ChatCommands */ |
|
14
|
|
|
protected $chatNotification; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* ChatCommandDataProvider constructor. |
|
18
|
|
|
* @param $chatCommands |
|
19
|
|
|
*/ |
|
20
|
7 |
|
public function __construct(ChatCommands $chatCommands, ChatNotificationInterface $chatNotification) |
|
21
|
|
|
{ |
|
22
|
7 |
|
$this->chatCommands = $chatCommands; |
|
23
|
7 |
|
$this->chatNotification = $chatNotification; |
|
|
|
|
|
|
24
|
7 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @inheritdoc |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function registerPlugin($pluginId, $pluginService) |
|
30
|
|
|
{ |
|
31
|
1 |
|
parent::registerPlugin($pluginId, $pluginService); |
|
32
|
|
|
|
|
33
|
1 |
|
$this->chatCommands->registerPlugin($pluginId, $pluginService); |
|
34
|
1 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @inheritdoc |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function deletePlugin($pluginId) |
|
40
|
|
|
{ |
|
41
|
1 |
|
parent::deletePlugin($pluginId); |
|
42
|
|
|
|
|
43
|
1 |
|
$this->chatCommands->deletePlugin($pluginId); |
|
44
|
1 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Called when a player chats on the server. |
|
48
|
|
|
* |
|
49
|
|
|
* @param int $playerUid |
|
50
|
|
|
* @param string $login |
|
51
|
|
|
* @param string $text |
|
52
|
|
|
* @param bool $isRegisteredCmd |
|
53
|
|
|
*/ |
|
54
|
4 |
|
public function onPlayerChat($playerUid, $login, $text, $isRegisteredCmd = false) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
4 |
|
if (!$isRegisteredCmd) { |
|
57
|
1 |
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
3 |
|
$cmdAndArgs = explode(' ', $text, 2); |
|
61
|
3 |
|
$cmdTxt = substr($cmdAndArgs[0], 1); |
|
62
|
3 |
|
$parameter = count($cmdAndArgs) > 1 ? $cmdAndArgs[1] : ''; |
|
63
|
|
|
|
|
64
|
|
|
// Internal dedicated serer command to ignore. |
|
65
|
3 |
|
if($cmdTxt === 'version') { |
|
66
|
1 |
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
$command = $this->chatCommands->getChatCommand($cmdTxt); |
|
70
|
2 |
|
if ($command && $command->validate($login, $parameter)) { |
|
71
|
1 |
|
$command->execute($login, $command->parseParameters($parameter)); |
|
72
|
|
|
} else { |
|
73
|
1 |
|
$this->chatNotification->sendMessage('expansion_core.chat_commands.wrong_chat', $login); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..