Completed
Pull Request — master (#165)
by
unknown
03:29
created

RestartMapVote::setMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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