Files
PocketMine-MP/src/event/player/PlayerCreationEvent.php
Dylan K. Taylor c8a7a53d70 event: modernize property declarations where possible
only private fields are modified; protected ones can't be changed in case someone extended the classes
2022-04-25 00:06:26 +01:00

93 lines
2.2 KiB
PHP

<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\event\player;
use pocketmine\event\Event;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\player\Player;
use pocketmine\utils\Utils;
use function is_a;
/**
* Allows the creation of players overriding the base Player class
*/
class PlayerCreationEvent extends Event{
/** @phpstan-var class-string<Player> */
private string $baseClass = Player::class;
/** @phpstan-var class-string<Player> */
private string $playerClass = Player::class;
public function __construct(private NetworkSession $session){}
public function getNetworkSession() : NetworkSession{
return $this->session;
}
public function getAddress() : string{
return $this->session->getIp();
}
public function getPort() : int{
return $this->session->getPort();
}
/**
* @return string
* @phpstan-return class-string<Player>
*/
public function getBaseClass(){
return $this->baseClass;
}
/**
* @param string $class
* @phpstan-param class-string<Player> $class
*/
public function setBaseClass($class) : void{
if(!is_a($class, $this->baseClass, true)){
throw new \RuntimeException("Base class $class must extend " . $this->baseClass);
}
$this->baseClass = $class;
}
/**
* @return string
* @phpstan-return class-string<Player>
*/
public function getPlayerClass(){
return $this->playerClass;
}
/**
* @param string $class
* @phpstan-param class-string<Player> $class
*/
public function setPlayerClass($class) : void{
Utils::testValidInstance($class, $this->baseClass);
$this->playerClass = $class;
}
}