<?php

namespace Robert\Sumo;

use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use Robert\Sumo\Arena\ArenaManager;
use Robert\Sumo\Commands\SumoCommand;
use Robert\Sumo\Events\EventListener;
use Robert\Sumo\Tasks\CountdownTask;

class Main extends PluginBase
{

    private $am;
    public $MOD_top_module;
    public function onEnable()
    {
    	$this->MOD_top_module = new Mod_TopModule($this);
        Server::getInstance()->getLogger()->info("Sumo enabled");
        $this->saveDefaultConfig();
        $this->am = new ArenaManager($this);
        $arena = $this->getConfig()->getNested("arenas");
        $this->getServer()->getCommandMap()->register("", new SumoCommand($this));
        foreach ($arena as $arenaname => $details) {
            $name = $arenaname;
            $spawn1 = $this->getConfig()->getNested("arenas.$arenaname.spawn1");

            $spawn2 = $this->getConfig()->getNested("arenas.$arenaname.spawn2");

            $this->am->registerArena($name, $spawn1, $spawn2);

            $this->getServer()->getLogger()->info("Registered arena " . $name);
        }
        $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
        $this->getServer()->getScheduler()->scheduleRepeatingTask(new CountdownTask($this), 20);
        foreach ($this->getHornyArenaManager()->getArenas() as $name => $arena) {
            $this->getServer()->getLogger()->info($name);
        }
    }
    public function onDisable()
    {
        Server::getInstance()->getLogger()->info("Sumo disabled");
    }

    public function getHornyArenaManager(): ArenaManager
    {
        return $this->am;
    }
}
