|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\AdminChat\ChatCommand; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups; |
|
6
|
|
|
use eXpansion\Framework\Core\Helpers\ChatNotification; |
|
7
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
|
8
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
9
|
|
|
use Monolog\Logger; |
|
10
|
|
|
use Psr\Log\LoggerInterface; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class ReasonUserCommand |
|
16
|
|
|
* |
|
17
|
|
|
* @author Reaby |
|
18
|
|
|
* @package eXpansion\Bundle\AdminChat\ChatCommand |
|
19
|
|
|
*/ |
|
20
|
|
View Code Duplication |
class AdminCommand extends AbstractConnectionCommand |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Description of the command. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $description; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Message to display in chat. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $chatMessage; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Name of the dedicated function to call. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $functionName; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritdoc |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function configure() |
|
47
|
|
|
{ |
|
48
|
|
|
parent::configure(); |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritdoc |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getDescription() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->description; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @inheritdoc |
|
62
|
|
|
*/ |
|
63
|
|
|
public function execute($login, InputInterface $input) |
|
64
|
|
|
{ |
|
65
|
|
|
$nickName = $this->playerStorage->getPlayerInfo($login)->getNickName(); |
|
66
|
|
|
$group = $this->adminGroupsHelper->getLoginUserGroups($login)->getName(); |
|
67
|
|
|
|
|
68
|
|
|
$this->chatNotification->sendMessage( |
|
69
|
|
|
$this->chatMessage, |
|
70
|
|
|
$this->isPublic ? null : $login, |
|
71
|
|
|
['%adminLevel%' => $group, '%admin%' => $nickName] |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$this->connection->{$this->functionName}(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $description |
|
79
|
|
|
*/ |
|
80
|
|
|
public function setDescription($description) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->description = $description; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $chatMessage |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setChatMessage($chatMessage) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->chatMessage = $chatMessage; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param string $functionName |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setFunctionName($functionName) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->functionName = $functionName; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.