<?php

namespace Lunarelly\Tasks;

use pocketmine\Player;
use pocketmine\Server;
use pocketmine\scheduler\PluginTask;
use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use Lunarelly\Main;

class HotBar extends PluginTask {
	
	public $pp;
	public $sa;
	
    public function __construct(Main $main) {
        $this->main = $main;
        parent::__construct($main);
    }

		public function onRun($currentTicks) {
			foreach($this->main->getServer()->getOnlinePlayers() as $p) {
		    	$this->pp = $this->main->getServer()->getPluginManager()->getPlugin("PurePerms");
	        	$this->sa = $this->main->getServer()->getPluginManager()->getPlugin("ServerAuth");
				$this->ea = $this->main->getServer()->getPluginManager()->getPlugin("EconomyAPI");

				$online = count($this->main->getServer()->getOnlinePlayers());
				$name = $p->getName();
				$date = date("d.m.y");
				$group = $this->pp->getUserDataMgr()->getGroup($p)->getName();
				$coins = $this->ea->myMoney($p);
				$map = $p->getLevel()->getFolderName();
                $upper = str_repeat("\n", 2);
				$right = str_repeat(" ", 75);
				$onlinemap = count($p->getLevel()->getPlayers());

				$sw = ["Shire", "Tribute", "Tron", "Aqua", "Islands", "Frostbite", "Galaxy", "Stations", "Rocky", "Country"];
				$mlg = ["Bricks", "Stones", "Clay", "Nether"];
				$lobby = ["lb", "leaderboards", "ml", "lbt", "sw"];
				$tnt = ["tnt3"];

				if($p->getLevel() === $this->main->getServer()->getDefaultLevel()) {
					if(!$this->sa->getAPI()->isPlayerAuthenticated($p)) {
						$p->sendTip("\n\n\n§fWelcome back, §a{$name} §8| §fOnline: §a{$online}");
                        if($group === "Owner"){
                            $p->sendTip("\n\n\n§fWelcome back, §fServer Owner §c@{$name} §8| §fOnline: §a{$online}");
                            }
                            
						} else {
						$p->sendTip("{$right}§bBlue§aGames\n{$right}§7{$date}\n\n{$right}§f§7Name: §a{$p->getName()}\n\n{$right}§f§7Rank: §a{$group}\n\n{$right}§f§7Coins: §a{$coins}\n\n{$right}§f§7Online: §a{$online}{$upper}");
						}
						}
						if(in_array($map, $tnt)) {
					    $p->sendTip("{$right}§cTNT§fRun\n{$right}§7{$date}\n\n{$right}§f§7Map: §e{$map}\n{$right}§f§7Players: §e{$onlinemap}\n\n{$right}");
						}
						if(in_array($map, $sw)) {
					    $p->sendTip("{$right}§bSky§fWars\n{$right}§7{$date}\n\n{$right}§f§7Map: §e{$map}\n\n{$right}§f§7Players: §e{$onlinemap}\n\n{$right}");
						}
						if(in_array($map, $mlg)) {
						$p->sendTip("{$right}§aMLG§fBlock\n{$right}§7{$date}\n\n{$right}§f§7Map: §e{$map}\n\n{$right}§f§7Players: §e{$onlinemap}\n\n");
						}
						if(in_array($map, $lobby)) {
						$p->sendTip("{$right}§eLobby\n{$right}§7{$date}\n\n{$right}§r§7Coins: §e{$coins}\n\n{$right}§r§7Online: §e{$online}");
						}
						}
						}
        private function getPingStatus($ping) {

        if ($ping > 320) {

            return "§8(§4High§8)";

        } elseif ($ping > 220) {

            return "§8(§eAverage§8)";

        } else {

            return "§8(§aNormal§8)";

        }

    }
					    }
						?>