BlockReGeneratorTask::__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\block\Block;
12
use pocketmine\scheduler\Task;
13
use VectorNetworkProject\TheMix\TheMix;
14
15
class BlockReGeneratorTask extends Task
16
{
17
    /** @var Block $block */
18
    private $block;
19
20
    public function __construct(Block $block)
21
    {
22
        $this->block = $block;
23
    }
24
25
    /**
26
     * @param int $currentTick
27
     */
28
    public function onRun(int $currentTick)
29
    {
30
        if (TheMix::getInstance()->getServer()->getLevelByName($this->getBlock()->getLevel()->getName())->getId() !== $this->getBlock()->getLevel()->getId()) {
31
            $this->getHandler()->cancel();
32
33
            return;
34
        }
35
        $this->getBlock()->getLevel()->setBlock($this->getBlock()->asVector3(), $this->block);
36
    }
37
38
    /**
39
     * @return Block
40
     */
41
    public function getBlock(): Block
42
    {
43
        return $this->block;
44
    }
45
}
46