<?php

namespace Lunarelly\Events;

use pocketmine\event\Listener;
use pocketmine\Player;
use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use pocketmine\event\player\PlayerPreLoginEvent;
use Lunarelly\Main;

class AntiBot implements Listener {

 	public function __construct(Main $main) {
 		$this->main = $main;
 	}

 	public function onLogin(PlayerPreLoginEvent $e) {
 		$p = $e->getPlayer();
 		$ip = $p->getAddress();
 		$count = 0;
 		foreach($this->main->getServer()->getOnlinePlayers() as $players) {
 			if($ip == $players->getAddress()) {
 				$count++;
 			}
 			if($count > 4) {
 				$this->main->getServer()->blockAddress($ip);
 			}
 		}
 	}
 }
?>