|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\DataProviders; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\DataProviders\Listener\ChatCommandInterface; |
|
6
|
|
|
use eXpansion\Framework\Core\Helpers\ChatOutput; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\ChatCommand\AbstractChatCommand; |
|
8
|
|
|
use eXpansion\Framework\Core\Model\Helpers\ChatNotificationInterface; |
|
9
|
|
|
use eXpansion\Framework\Core\Services\ChatCommands; |
|
10
|
|
|
|
|
11
|
|
|
use /** @noinspection PhpUndefinedClassInspection */ |
|
12
|
|
|
Symfony\Component\Console\Exception\RuntimeException; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class ChatCommandDataProvider, provides execution instructions for chat commands. |
|
16
|
|
|
* |
|
17
|
|
|
* @package eXpansion\Framework\Core\DataProviders |
|
18
|
|
|
*/ |
|
19
|
|
|
class ChatCommandDataProvider extends AbstractDataProvider |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var ChatCommands */ |
|
22
|
|
|
protected $chatCommands; |
|
23
|
|
|
|
|
24
|
|
|
/** @var ChatCommands */ |
|
25
|
|
|
protected $chatNotification; |
|
26
|
|
|
|
|
27
|
|
|
/** @var ChatOutput */ |
|
28
|
|
|
protected $chatOutput; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* ChatCommandDataProvider constructor. |
|
32
|
|
|
* @param ChatCommands $chatCommands |
|
33
|
|
|
* @param ChatNotificationInterface $chatNotification |
|
34
|
|
|
* @param ChatOutput $chatOutput |
|
35
|
|
|
*/ |
|
36
|
7 |
|
public function __construct( |
|
37
|
|
|
ChatCommands $chatCommands, |
|
38
|
|
|
ChatNotificationInterface $chatNotification, |
|
39
|
|
|
ChatOutput $chatOutput |
|
40
|
|
|
) { |
|
41
|
7 |
|
$this->chatCommands = $chatCommands; |
|
42
|
7 |
|
$this->chatNotification = $chatNotification; |
|
|
|
|
|
|
43
|
7 |
|
$this->chatOutput = $chatOutput; |
|
44
|
7 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @inheritdoc |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function registerPlugin($pluginId, $pluginService) |
|
50
|
|
|
{ |
|
51
|
1 |
|
parent::registerPlugin($pluginId, $pluginService); |
|
52
|
|
|
|
|
53
|
|
|
/** @var ChatCommandInterface|object $pluginService */ |
|
54
|
1 |
|
$this->chatCommands->registerPlugin($pluginId, $pluginService); |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @inheritdoc |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public function deletePlugin($pluginId) |
|
61
|
|
|
{ |
|
62
|
1 |
|
parent::deletePlugin($pluginId); |
|
63
|
|
|
|
|
64
|
1 |
|
$this->chatCommands->deletePlugin($pluginId); |
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Called when a player chats on the server. |
|
69
|
|
|
* |
|
70
|
|
|
* @param int $playerUid |
|
71
|
|
|
* @param string $login |
|
72
|
|
|
* @param string $text |
|
73
|
|
|
* @param bool $isRegisteredCmd |
|
74
|
|
|
*/ |
|
75
|
4 |
|
public function onPlayerChat($playerUid, $login, $text, $isRegisteredCmd = false) |
|
76
|
|
|
{ |
|
77
|
|
|
// disable for server |
|
78
|
4 |
|
if ($playerUid === 0) { |
|
79
|
|
|
return; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
4 |
|
if (!$isRegisteredCmd) { |
|
83
|
2 |
|
return; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
3 |
|
$text = substr($text, 1); |
|
87
|
3 |
|
$cmdAndArgs = explode(' ', $text); |
|
88
|
|
|
|
|
89
|
|
|
// Internal dedicated server command to ignore. |
|
90
|
3 |
|
if ($cmdAndArgs[0] === 'version') { |
|
91
|
1 |
|
return; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
// Internal dedicated server command to ignore. |
|
95
|
2 |
|
if ($cmdAndArgs[0] === 'serverlogin') { |
|
96
|
|
|
return; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
2 |
|
$message = 'expansion_core.chat_commands.wrong_chat'; |
|
100
|
|
|
|
|
101
|
2 |
|
list($command, $parameter) = $this->chatCommands->getChatCommand($cmdAndArgs); |
|
102
|
|
|
/** @var AbstractChatCommand $command */ |
|
103
|
2 |
|
if ($command) { |
|
104
|
1 |
|
$parameter = implode(" ", $parameter); |
|
105
|
1 |
|
$message = $command->validate($login, $parameter); |
|
106
|
1 |
|
if (empty($message)) { |
|
107
|
|
|
try { |
|
108
|
1 |
|
$this->chatOutput->setLogin($login); |
|
109
|
1 |
|
$message = $command->run($login, $this->chatOutput, $parameter); |
|
110
|
|
|
} /** @noinspection PhpUndefinedClassInspection */ |
|
111
|
|
|
catch (RuntimeException $e) { |
|
112
|
|
|
$this->chatNotification->sendMessage($e->getMessage(), $login); |
|
|
|
|
|
|
113
|
|
|
} catch (\Exception $e) { |
|
114
|
|
|
$this->chatNotification->sendMessage($e->getMessage(), $login); |
|
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
2 |
|
if (!empty($message)) { |
|
120
|
1 |
|
$this->chatNotification->sendMessage($message, $login); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
2 |
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
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..