<?php

namespace bedwars\entity;

use bedwars\BedWars;

class BedWarsWins extends NPC {

	/** @var int */
	private $canUpdate;
	
	/**
	 * @param float $currentTicks
	 * @param return bool
     */
	public function onUpdate($currentTicks) {
		if ($this->closed) {
			return false;
		}

		if ($this->canUpdate++ >= 25) {
			$this->canUpdate = 0;
			$plugin = BedWars::$loaded;
			$lines = ['§l§2Top Wins', '§7All Modes', ''];

			if ($plugin instanceof BedWars) {
				$list = $plugin->topWins->getAll();
				
				if (count($list) > 0) {
					arsort($list);

					$i = 1;
					foreach ($list as $username => $count) {
						$lines[] = "§2{$i}. §7{$username} : §f{$count}";

						if ($i >= 10) {
							break;
						} else if ($i == 1) {
							$lines[] = '';
						}
						$i++;
					}
				} else {
					$lines[] = "§cNo Players!";
				}
			} else {
				$lines[] = "§cInstall The BedWars Plugin!";
			}
			$this->addLines($lines);
		}
		return parent::onUpdate($currentTicks);
	}
}
?>