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

VoteManager::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;
4
5
use eXpansion\Bundle\Maps\Services\JukeboxService;
6
use eXpansion\Bundle\VoteManager\Plugins\Gui\Widget\UpdateVoteWidgetFactory;
7
use eXpansion\Bundle\VoteManager\Plugins\Gui\Widget\VoteWidgetFactory;
8
use eXpansion\Bundle\VoteManager\Plugins\Votes\AbstractVotePlugin;
9
use eXpansion\Bundle\VoteManager\Services\VoteService;
10
use eXpansion\Bundle\VoteManager\Structures\Vote;
11
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpTimer;
12
use eXpansion\Framework\Core\Helpers\ChatNotification;
13
use eXpansion\Framework\Core\Model\UserGroups\Group;
14
use eXpansion\Framework\Core\Services\Console;
15
use eXpansion\Framework\Core\Storage\Data\Player;
16
use eXpansion\Framework\Core\Storage\MapStorage;
17
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyVote;
18
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpScriptPodium;
19
use Maniaplanet\DedicatedServer\Connection;
20
21
class VoteManager implements ListenerInterfaceMpLegacyVote, ListenerInterfaceExpTimer
22
{
23
    const YES = "yes";
24
    const NO = "no";
25
26
    /**
27
     * @var VoteWidgetFactory
28
     */
29
    private $voteWidgetFactory;
30
31
    /**
32
     * @var UpdateVoteWidgetFactory
33
     */
34
    private $updateVoteWidgetFactory;
35
36
    /**
37
     * @var Group
38
     */
39
    private $players;
40
41
    /**
42
     * @var VoteService
43
     */
44
    private $voteService;
45
46
    /**
47
     * VoteManager constructor.
48
     *
49
     * @param VoteWidgetFactory $voteWidgetFactory
50
     * @param UpdateVoteWidgetFactory $updateVoteWidgetFactory
51
     * @param Group $players
52
     * @param VoteService $voteService
53
     */
54 7
    public function __construct(
55
        VoteWidgetFactory $voteWidgetFactory,
56
        UpdateVoteWidgetFactory $updateVoteWidgetFactory,
57
        Group $players,
58
        VoteService $voteService
59
    ) {
60 7
        $this->voteWidgetFactory = $voteWidgetFactory;
61 7
        $this->players = $players;
62 7
        $this->voteService = $voteService;
63 7
        $this->updateVoteWidgetFactory = $updateVoteWidgetFactory;
64 7
    }
65
66
    /**
67
     * When a new vote is addressed
68
     *
69
     * @param Player $player
70
     * @param string $cmdName
71
     * @param string $cmdValue
72
     *
73
     * @return void
74
     */
75 2
    public function onVoteNew(Player $player, $cmdName, $cmdValue)
76
    {
77 2
        if ($cmdValue instanceof Vote) {
78 1
            $this->updateVoteWidgetFactory->create($this->players);
79 1
            $this->voteWidgetFactory->create($this->players);
80 1
            $this->voteWidgetFactory->setMessage($this->voteService->getCurrentVote()->getQuestion());
81
        } else {
82 1
            $this->voteService->startVote($player, $cmdName, ['value' => $cmdValue]);
83
        }
84 2
    }
85
86
    /**
87
     * When vote gets cancelled
88
     *
89
     * @param Player $player
90
     * @param string $cmdName
91
     * @param string $cmdValue
92
     *
93
     * @return void
94
     */
95 1
    public function onVoteCancelled(Player $player, $cmdName, $cmdValue)
96
    {
97
98 1
        if ($cmdValue instanceof Vote) {
99 1
            $this->voteWidgetFactory->destroy($this->players);
100 1
            $this->updateVoteWidgetFactory->destroy($this->players);
101
        } else {
102
            $this->voteService->cancel();
103
        }
104 1
    }
105
106
    /**
107
     * When vote Passes
108
     * @param Player $player
109
     * @param string $cmdName
110
     * @param string $cmdValue
111
     *
112
     * @return void
113
     */
114 1
    public function onVotePassed(Player $player, $cmdName, $cmdValue)
115
    {
116 1
        if ($cmdValue instanceof Vote) {
117 1
            $this->voteWidgetFactory->destroy($this->players);
118 1
            $this->updateVoteWidgetFactory->destroy($this->players);
119
        }
120 1
    }
121
122
    /**
123
     * When vote Fails
124
     * @param Player $player
125
     * @param string $cmdName
126
     * @param string $cmdValue
127
     *
128
     * @return void
129
     */
130 1
    public function onVoteFailed(Player $player, $cmdName, $cmdValue)
131
    {
132 1
        if ($cmdValue instanceof Vote) {
133 1
            $this->voteWidgetFactory->destroy($this->players);
134 1
            $this->updateVoteWidgetFactory->destroy($this->players);
135
        }
136 1
    }
137
138 1
    public function onEverySecond()
139
    {
140 1
        if ($this->voteService->getCurrentVote() instanceof AbstractVotePlugin) {
141 1
            $this->voteService->update();
142 1
            $this->updateVoteWidgetFactory->update($this->players);
143
        }
144 1
    }
145
146 1
    public function onPreLoop()
147
    {
148
        // Nothing
149 1
    }
150
151 1
    public function onPostLoop()
152
    {
153
        // Nothing
154 1
    }
155
156
}
157
158