mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Removed pocketmine subdirectory, map PSR-4 style
This commit is contained in:
108
src/event/player/PlayerCreationEvent.php
Normal file
108
src/event/player/PlayerCreationEvent.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?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 function is_a;
|
||||
|
||||
/**
|
||||
* Allows the creation of players overriding the base Player class
|
||||
*/
|
||||
class PlayerCreationEvent extends Event{
|
||||
|
||||
/** @var NetworkSession */
|
||||
private $session;
|
||||
|
||||
/** @var Player::class */
|
||||
private $baseClass = Player::class;
|
||||
/** @var Player::class */
|
||||
private $playerClass = Player::class;
|
||||
|
||||
|
||||
/**
|
||||
* @param NetworkSession $session
|
||||
*/
|
||||
public function __construct(NetworkSession $session){
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return NetworkSession
|
||||
*/
|
||||
public function getNetworkSession() : NetworkSession{
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddress() : string{
|
||||
return $this->session->getIp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPort() : int{
|
||||
return $this->session->getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player::class
|
||||
*/
|
||||
public function getBaseClass(){
|
||||
return $this->baseClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player::class $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 Player::class
|
||||
*/
|
||||
public function getPlayerClass(){
|
||||
return $this->playerClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player::class $class
|
||||
*/
|
||||
public function setPlayerClass($class) : void{
|
||||
if(!is_a($class, $this->baseClass, true)){
|
||||
throw new \RuntimeException("Class $class must extend " . $this->baseClass);
|
||||
}
|
||||
|
||||
$this->playerClass = $class;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user