Completed
Pull Request — master (#307)
by
unknown
03:53
created

RestartMapVote::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 7
dl 0
loc 16
ccs 0
cts 6
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace eXpansion\Bundle\VoteManager\Plugins\Votes;
4
5
use eXpansion\Bundle\Maps\Services\JukeboxService;
6
use eXpansion\Framework\Core\Helpers\ChatNotification;
7
use eXpansion\Framework\Core\Services\Application\Dispatcher;
8
use eXpansion\Framework\Core\Storage\Data\Player;
9
use eXpansion\Framework\Core\Storage\MapStorage;
10
use eXpansion\Framework\Core\Storage\PlayerStorage;
11
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpScriptPodium;
12
use Maniaplanet\DedicatedServer\Structures\Map;
13
14
/**
15
 * Class NextMapVote
16
 *
17
 * @author    de Cramer Oliver<[email protected]>
18
 * @copyright 2017 eXpansion
19
 * @package   eXpansion\Bundle\VoteManager\Plugins\Votes
20
 */
21
class RestartMapVote extends AbstractVotePlugin implements ListenerInterfaceMpScriptPodium
22
{
23
    /** @var Map */
24
    private $map;
25
26
    /** @var JukeboxService */
27
    protected $jukebox;
28
29
    /** @var MapStorage */
30
    protected $mapStorage;
31
32
    /** @var ChatNotification */
33
    protected $chatNotification;
34
35
    /**
36
     * RestartMapVote constructor.
37
     *
38
     * @param Dispatcher       $dispatcher
39
     * @param PlayerStorage    $playerStorage
40
     * @param JukeboxService   $jukebox
41
     * @param MapStorage       $mapStorage
42
     * @param ChatNotification $chatNotification
43
     * @param int              $duration
44
     * @param float            $ratio
45
     */
46
    public function __construct(
47
        Dispatcher $dispatcher,
48
        PlayerStorage $playerStorage,
49
        JukeboxService $jukebox,
50
        MapStorage $mapStorage,
51
        ChatNotification $chatNotification,
52
        int $duration,
53
        float $ratio
54
    ) {
55
        parent::__construct($dispatcher, $playerStorage, $duration, $ratio);
56
57
        $this->jukebox = $jukebox;
58
        $this->mapStorage = $mapStorage;
59
60
        $this->chatNotification = $chatNotification;
61
    }
62
63
    public function start(Player $player, $params)
64
    {
65
        $this->map = $this->mapStorage->getCurrentMap();
66
67
        return parent::start($player, $params);
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function getQuestion(): string
74
    {
75
        return 'expansion_votemanager.restartmap.question';
76
    }
77
78
    /**
79
     * @inheritdoc
80
     */
81
    public function executeVotePassed()
82
    {
83
        $this->jukebox->addMap($this->map, $this->getCurrentVote()->getPlayer()->getLogin(),
84
            true, true);
85
        $this->chatNotification->sendMessage("|info| Vote passed. Will replay map!");
86
    }
87
88
    /**
89
     * @inheritdoc
90
     */
91
    protected function executeVoteFailed()
92
    {
93
        // Do Nothing
94
    }
95
96
    /**
97
     * Get type code of this vote.
98
     *
99
     * @return string
100
     */
101
    public function getCode(): string
102
    {
103
        return 'Exp_RestartMap';
104
    }
105
106
    /**
107
     * Get native votes this votes replaces.
108
     *
109
     * @return string[]
110
     */
111
    public function getReplacementTypes(): array
112
    {
113
        return ['RestartMap'];
114
    }
115
116
    /**
117
     * Callback sent when the "onPodiumStart" section start.
118
     *
119
     * @param int $time Server time when the callback was sent
120
     * @return void
121
     */
122
    public function onPodiumStart($time)
123
    {
124
        //nothing
125
    }
126
127
    /**
128
     * Callback sent when the "onPodiumEnd" section end.
129
     *
130
     * @param int $time Server time when the callback was sent
131
     *
132
     * @return void
133
     */
134
    public function onPodiumEnd($time)
135
    {
136
        $this->cancel();
137
    }
138
}
139