PhaseTask::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Copyright (c) 2018 VectorNetworkProject. All rights reserved. MIT license.
4
 *
5
 * GitHub: https://github.com/VectorNetworkProject/TheMix
6
 * Website: https://www.vector-network.tk
7
 */
8
9
namespace VectorNetworkProject\TheMix\task;
10
11
use pocketmine\scheduler\Task;
12
use VectorNetworkProject\TheMix\game\corepvp\PhaseManager;
13
use VectorNetworkProject\TheMix\game\event\game\PhaseTimeUpdateEvent;
14
15
class PhaseTask extends Task
16
{
17
    /** @var int $time */
18
    private static $time;
19
20
    /**
21
     * PhaseTask constructor.
22
     *
23
     * @param int $time
24
     */
25
    public function __construct(int $time = 600)
26
    {
27
        self::$time = $time;
28
    }
29
30
    /**
31
     * @param int $currentTick
32
     *
33
     * @throws \ReflectionException
34
     */
35
    public function onRun(int $currentTick)
36
    {
37
        $event = new PhaseTimeUpdateEvent(self::getTime() - 1, PhaseManager::getPhase());
38
        $event->call();
39
        if (!$event->isCancelled()) {
40
            self::setTime($this->getTime() - 1);
41
        }
42
    }
43
44
    /**
45
     * @return int
46
     */
47
    public static function getTime(): int
48
    {
49
        return self::$time;
50
    }
51
52
    /**
53
     * @param int $time
54
     */
55
    public static function setTime(int $time = 600): void
56
    {
57
        self::$time = $time;
58
    }
59
}
60