Completed
Pull Request — master (#175)
by
unknown
05:30
created

RestartMapVote::onPodiumStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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