<?php

namespace bedwars\scheduler;

use pocketmine\scheduler\PluginTask;

use bedwars\BedWars;
use bedwars\Mod_TopModule;
use BedWars\game\Game;

class GameTask extends PluginTask {

	/** @var int */
	const delay = 20; //20ticks = 1s	

	/*
	* @param BedWars $plugin 
	*/
	public function __construct(BedWars $plugin) {
		parent::__construct($plugin);
	}

	/*
	* @param BedWars $plugin 
	*/
	public static function init(BedWars $plugin) {
		$plugin->getServer()->getScheduler()->scheduleRepeatingTask(new GameTask($plugin), GameTask::delay);
	}

	/**
	* @param int $currentTicks 
	*/
	public function onRun($currentTicks) {
		$count = 0;

		foreach ($this->getOwner()->arenas as $key => $value) {
			if ($value instanceof Game) {
				$value->onUpdate();
				$count++;
			}
		} 
	}
}
?>