diff --git a/src/pocketmine/event/player/PlayerCreationEvent.php b/src/pocketmine/event/player/PlayerCreationEvent.php new file mode 100644 index 000000000..18e811340 --- /dev/null +++ b/src/pocketmine/event/player/PlayerCreationEvent.php @@ -0,0 +1,127 @@ +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; + } + +} \ No newline at end of file diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index c9b6627c2..ec5d01441 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -24,6 +24,7 @@ */ namespace pocketmine\network; +use pocketmine\event\player\PlayerCreationEvent; use pocketmine\network\protocol\AddEntityPacket; use pocketmine\network\protocol\AddItemEntityPacket; use pocketmine\network\protocol\AddMobPacket; @@ -167,7 +168,11 @@ class RakLibInterface implements ServerInstance, SourceInterface{ } public function openSession($identifier, $address, $port, $clientID){ - $player = new Player($this, null, $address, $port); + $ev = new PlayerCreationEvent($this, Player::class, Player::class, null, $address, $port); + $this->server->getPluginManager()->callEvent($ev); + $class = $ev->getPlayerClass(); + + $player = new $class($this, $ev->getClientId(), $ev->getAddress(), $ev->getPort()); $this->players[$identifier] = $player; $this->identifiersACK[$identifier] = 0; $this->identifiers->attach($player, $identifier); diff --git a/src/raklib b/src/raklib index 658529ec4..7e1bc7d62 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 658529ec44f30ce210f5cf42d2280e51332fe3d0 +Subproject commit 7e1bc7d62b7ff024f8a468973af8d3ab71e63dcc