TheMix   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 22

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 22
dl 0
loc 82
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A onLoad() 0 12 2
A onEnable() 0 26 2
A onDisable() 0 4 1
A getInstance() 0 4 1
A registerCommands() 0 10 1
A registerEvents() 0 10 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;
10
11
use InkoHX\GoldLibrary\GoldAPI;
12
use InkoHX\LeveLibrary\LevelAPI;
13
use pocketmine\plugin\PluginBase;
14
use pocketmine\utils\TextFormat;
15
use tokyo\pmmp\libform\FormApi;
16
use VectorNetworkProject\TheMix\command\defaults\DiscordCommand;
17
use VectorNetworkProject\TheMix\command\defaults\ModeratorCommand;
18
use VectorNetworkProject\TheMix\command\defaults\PingCommand;
19
use VectorNetworkProject\TheMix\command\defaults\TpsCommand;
20
use VectorNetworkProject\TheMix\command\Permissions;
21
use VectorNetworkProject\TheMix\event\BlockEventListener;
22
use VectorNetworkProject\TheMix\event\EntityEventListener;
23
use VectorNetworkProject\TheMix\event\GameEventListener;
24
use VectorNetworkProject\TheMix\event\LevelEventListener;
25
use VectorNetworkProject\TheMix\event\LibraryEventListener;
26
use VectorNetworkProject\TheMix\event\PlayerEventListener;
27
use VectorNetworkProject\TheMix\game\DefaultConfig;
28
use VectorNetworkProject\TheMix\task\PhaseTask;
29
30
class TheMix extends PluginBase
31
{
32
    public const VERSION = 8;
33
34
    /* @var TheMix $instance */
35
    private static $instance = null;
36
37
    public function onLoad()
38
    {
39
        $this->getLogger()->notice('Loading System...');
40
        self::$instance = $this;
41
        $this->saveDefaultConfig();
42
        DefaultConfig::getVersion() === self::VERSION
43
            ? $this->getLogger()->info('Loaded Config')
44
            : $this->getLogger()->alert('Please update config.yml');
45
        LevelAPI::init();
46
        GoldAPI::init();
47
        date_default_timezone_set(DefaultConfig::getTimezone());
48
    }
49
50
    public function onEnable()
51
    {
52
        Permissions::registers();
53
        FormApi::register($this);
54
        $this->registerCommands();
55
        $this->registerEvents();
56
        $this->getScheduler()->scheduleRepeatingTask(new PhaseTask(), 20);
57
        $this->getServer()->loadLevel(DefaultConfig::getStageLevelName())
58
            ? $this->getLogger()->notice('Loaded stage.')
59
            : $this->getServer()->generateLevel(DefaultConfig::getStageLevelName());
60
        $this->getLogger()->notice(TextFormat::RED.'
61
        
62
        
63
        ▄▄▄█████▓ ██░ ██ ▓█████     ███▄ ▄███▓ ██▓▒██   ██▒
64
        ▓  ██▒ ▓▒▓██░ ██▒▓█   ▀    ▓██▒▀█▀ ██▒▓██▒▒▒ █ █ ▒░
65
        ▒ ▓██░ ▒░▒██▀▀██░▒███      ▓██    ▓██░▒██▒░░  █   ░
66
        ░ ▓██▓ ░ ░▓█ ░██ ▒▓█  ▄    ▒██    ▒██ ░██░ ░ █ █ ▒ 
67
          ▒██▒ ░ ░▓█▒░██▓░▒████▒   ▒██▒   ░██▒░██░▒██▒ ▒██▒
68
        ▒ ░░    ▒ ░░▒░▒░░ ▒░ ░   ░ ▒░   ░  ░░▓  ▒▒ ░ ░▓ ░
69
        ░     ▒ ░▒░ ░ ░ ░  ░   ░  ░      ░ ▒ ░░░   ░▒ ░
70
        ░       ░  ░░ ░   ░      ░      ░    ▒ ░ ░    ░  
71
                ░  ░  ░   ░  ░          ░    ░   ░    ░  
72
                                                   
73
    §7Copyright (c) 2018 VectorNetworkProject. All rights reserved.
74
        ');
75
    }
76
77
    public function onDisable()
78
    {
79
        $this->getLogger()->notice('Unload System...');
80
    }
81
82
    /**
83
     * @return TheMix
84
     */
85
    public static function getInstance(): self
86
    {
87
        return self::$instance;
88
    }
89
90
    private function registerCommands(): void
91
    {
92
        $commands = [
93
            new PingCommand($this),
94
            new TpsCommand($this),
95
            new ModeratorCommand($this),
96
            new DiscordCommand($this),
97
        ];
98
        $this->getServer()->getCommandMap()->registerAll($this->getName(), $commands);
99
    }
100
101
    private function registerEvents(): void
102
    {
103
        $plm = $this->getServer()->getPluginManager();
104
        $plm->registerEvents(new BlockEventListener(), $this);
105
        $plm->registerEvents(new EntityEventListener(), $this);
106
        $plm->registerEvents(new GameEventListener(), $this);
107
        $plm->registerEvents(new LevelEventListener(), $this);
108
        $plm->registerEvents(new LibraryEventListener(), $this);
109
        $plm->registerEvents(new PlayerEventListener(), $this);
110
    }
111
}
112