BlockReGeneratorTask   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onRun() 0 9 2
A getBlock() 0 4 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