SpawnManager::PlayerReSpawn()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
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\game\corepvp;
10
11
use pocketmine\entity\Effect;
12
use pocketmine\entity\EffectInstance;
13
use pocketmine\level\Position;
14
use pocketmine\Player;
15
use pocketmine\Server;
16
use VectorNetworkProject\TheMix\game\corepvp\blue\BlueSpawnManager;
17
use VectorNetworkProject\TheMix\game\corepvp\blue\BlueTeamManager;
18
use VectorNetworkProject\TheMix\game\corepvp\red\RedSpawnManager;
19
use VectorNetworkProject\TheMix\game\corepvp\red\RedTeamManager;
20
use VectorNetworkProject\TheMix\game\DefaultConfig;
21
use VectorNetworkProject\TheMix\game\kit\BlueKit;
22
use VectorNetworkProject\TheMix\game\kit\RedKit;
23
use VectorNetworkProject\TheMix\task\ReSpawnCooldownTask;
24
use VectorNetworkProject\TheMix\TheMix;
25
26
class SpawnManager
0 ignored issues
show
Coding Style introduced by
SpawnManager does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
27
{
28
    /**
29
     * @param Player $player
30
     */
31
    public static function PlayerReSpawn(Player $player)
0 ignored issues
show
Coding Style introduced by
function PlayerReSpawn() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
32
    {
33
        if (RedTeamManager::isJoined($player)) {
34
            self::ReSpawnCooldown($player, RedSpawnManager::getRandomPosition());
0 ignored issues
show
Bug introduced by
It seems like \VectorNetworkProject\Th...er::getRandomPosition() can be null; however, ReSpawnCooldown() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
35
            RedKit::sendItem($player);
36
        } elseif (BlueTeamManager::isJoined($player)) {
37
            self::ReSpawnCooldown($player, BlueSpawnManager::getRandomPosition());
0 ignored issues
show
Bug introduced by
It seems like \VectorNetworkProject\Th...er::getRandomPosition() can be null; however, ReSpawnCooldown() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
38
            BlueKit::sendItems($player);
39
        } else {
40
            self::ReSpawnCooldown($player, Server::getInstance()->getDefaultLevel()->getSpawnLocation());
41
        }
42
    }
43
44
    /**
45
     * @param Player   $player
46
     * @param Position $position
47
     */
48
    private static function ReSpawnCooldown(Player $player, Position $position): void
0 ignored issues
show
Coding Style introduced by
function ReSpawnCooldown() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
49
    {
50
        $player->addTitle('§l§cYOU DIED', 'あなたは死んでしまった!5秒後行動可能になります。', 20, 100, 20);
51
        $player->teleport(new Position(0, 80, 0, Server::getInstance()->getLevelByName(DefaultConfig::getStageLevelName())));
52
        $player->setGamemode(Player::SPECTATOR);
53
        $player->setHealth(20);
54
        $player->setMaxHealth(20);
55
        $player->setFood(20);
56
        $player->getInventory()->clearAll();
57
        $player->getArmorInventory()->clearAll();
58
        $player->removeAllEffects();
59
        $player->addEffect(new EffectInstance(Effect::getEffect(Effect::NIGHT_VISION), 99999999 * 20, 11, false));
0 ignored issues
show
Bug introduced by
It seems like \pocketmine\entity\Effec...y\Effect::NIGHT_VISION) can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
60
        TheMix::getInstance()->getScheduler()->scheduleDelayedTask(new ReSpawnCooldownTask($player, $position), 100);
61
    }
62
}
63