Completed
Push — master ( 188bc3...1f1d6f )
by De Cramer
9s
created

TotoPlugin::onPlayerChat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
namespace eXpansion\Bundle\Acme\Plugins;
4
5
use eXpansion\Core\DataProviders\Listener\ChatDataListenerInterface;
6
use eXpansion\Core\Model\UserGroups\Group;
7
use eXpansion\Core\Plugins\Gui\GroupManialinkFactory;
8
use eXpansion\Core\Plugins\Gui\ManialinkFactory;
9
use eXpansion\Core\Services\Console;
10
use eXpansion\Core\Storage\Data\Player;
11
12
/**
13
 * TotoPlugin is a test plugin to be removed.
14
 *
15
 * @package eXpansion\Core\Plugins
16
 */
17
class TotoPlugin implements ChatDataListenerInterface, StatusAwarePluginInterface
18
{
19
    /** @var Console  */
20
    protected $console;
21
22
    /** @var ManialinkFactory */
23
    protected $mlFactory;
24
25
    /** @var Group  */
26
    protected $playersGroup;
27
28
    function __construct(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
        Console $console,
30
        ManialinkFactory $mlFactory,
31
        Group $players
32
    )
33
    {
34
        $this->console = $console;
35
        $this->mlFactory = $mlFactory;
36
        $this->playersGroup = $players;
37
    }
38
39
    public function onPlayerChat(Player $player, $text)
40
    {
41
        $text = trim($text);
42
        $from = trim($player->getNickName());
43
        if ($player->getPlayerId() === 0) {
44
            $from = '$777Console';
45
        }
46
47
        $this->console->writeln($from . $text);
48
    }
49
50
51
    /**
52
     * Set the status of the plugin
53
     *
54
     * @param boolean $status
55
     *
56
     * @return null
57
     */
58
    public function setStatus($status)
59
    {
60
        if ($status) {
61
            $this->mlFactory->create($this->playersGroup);
62
        } else {
63
            $this->mlFactory->destroy($this->playersGroup);
64
        }
65
    }
66
}
67