Added PlayerCreationEvent

This commit is contained in:
Shoghi Cervantes
2015-01-03 16:38:00 +01:00
parent 074c8b876d
commit 7ef8edccf4
3 changed files with 134 additions and 2 deletions

View File

@ -0,0 +1,127 @@
<?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/
*
*
*/
namespace pocketmine\event\player;
use pocketmine\event\Event;
use pocketmine\network\SourceInterface;
use pocketmine\Player;
/**
* Allows the creation of players overriding the base Player class
*/
class PlayerCreationEvent extends Event{
public static $handlerList = null;
public static $eventPool = [];
public static $nextEvent = 0;
/** @var SourceInterface */
private $interface;
/** @var mixed */
private $clientId;
/** @var string */
private $address;
/** @var int */
private $port;
/** @var Player::class */
private $baseClass;
/** @var Player::class */
private $playerClass;
/**
* @param SourceInterface $interface
* @param Player::class $baseClass
* @param Player::class $playerClass
* @param mixed $clientId
* @param string $address
* @param int $port
*/
public function __construct(SourceInterface $interface, $baseClass, $playerClass, $clientId, $address, $port){
$this->interface = $interface;
$this->clientId = $clientId;
$this->address = $address;
$this->port = $port;
if(!is_subclass_of($baseClass, Player::class, true)){
throw new \RuntimeException("Base class $baseClass must extend " . Player::class);
}
$this->baseClass = $baseClass;
if(!is_subclass_of($playerClass, Player::class, true)){
throw new \RuntimeException("Class $playerClass must extend " . Player::class);
}
$this->playerClass = $playerClass;
}
/**
* @return SourceInterface
*/
public function getInterface(){
return $this->interface;
}
/**
* @return string
*/
public function getAddress(){
return $this->address;
}
/**
* @return int
*/
public function getPort(){
return $this->port;
}
/**
* @return mixed
*/
public function getClientId(){
return $this->clientId;
}
/**
* @return Player::class
*/
public function getBaseClass(){
return $this->baseClass;
}
/**
* @return Player::class
*/
public function getPlayerClass(){
return $this->playerClass;
}
public function setPlayerClass($class){
if(!is_subclass_of($class, $this->baseClass, true)){
throw new \RuntimeException("Class $class must extend " . $this->baseClass);
}
$this->playerClass = $class;
}
}