UpdateScoreboardTask::onRun()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
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 InkoHX\GoldLibrary\GoldAPI;
12
use InkoHX\LeveLibrary\LevelAPI;
13
use Miste\scoreboardspe\API\Scoreboard;
14
use pocketmine\Player;
15
use pocketmine\scheduler\Task;
16
use VectorNetworkProject\TheMix\game\corepvp\blue\BlueCoreManager;
17
use VectorNetworkProject\TheMix\game\corepvp\red\RedCoreManager;
18
use VectorNetworkProject\TheMix\game\streak\Streak;
19
20
class UpdateScoreboardTask extends Task
21
{
22
    /* @var Scoreboard $scoreboard */
23
    private $scoreboard;
24
25
    /* @var Player $player */
26
    private $player;
27
28
    /**
29
     * UpdateScoreboardTask constructor.
30
     *
31
     * @param Scoreboard $scoreboard
32
     * @param Player     $player
33
     */
34
    public function __construct(Scoreboard $scoreboard, Player $player)
35
    {
36
        $this->scoreboard = $scoreboard;
37
        $this->player = $player;
38
    }
39
40
    /**
41
     * @param int $currentTick
42
     */
43
    public function onRun(int $currentTick)
44
    {
45
        if (!$this->player->isOnline()) {
46
            $this->getHandler()->cancel();
47
48
            return;
49
        }
50
        $scoreboard = $this->scoreboard;
51
        $scoreboard->setLine($this->player, 0, '§7'.date('Y/m/d H:i:s'));
52
        $scoreboard->setLine($this->player, 2, '§l§cRED§r§7: §a'.RedCoreManager::getHP());
53
        $scoreboard->setLine($this->player, 3, '§l§bBLUE§r§7: §a'.BlueCoreManager::getHP());
54
        $scoreboard->setLine($this->player, 5, 'Level: '.LevelAPI::getLevel($this->player));
55
        $scoreboard->setLine($this->player, 6, 'Needed XP: §b'.LevelAPI::NeededXP($this->player));
56
        $scoreboard->setLine($this->player, 7, 'Gold: §6'.GoldAPI::getGold($this->player).'g');
57
        $scoreboard->setLine($this->player, 9, 'Streak: §c'.Streak::getStreak($this->player));
58
        $scoreboard->setLine($this->player, 10, 'Event: none');
59
        $scoreboard->setLine($this->player, 12, '§ewww.vector-network.tk  ');
60
    }
61
}
62