mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
HandshakePacketHandler no longer depends on NetworkSession
This commit is contained in:
parent
7d9df6af6f
commit
c869a7f099
@ -548,7 +548,9 @@ class NetworkSession{
|
||||
|
||||
$this->cipher = new NetworkCipher($encryptionKey);
|
||||
|
||||
$this->setHandler(new HandshakePacketHandler($this));
|
||||
$this->setHandler(new HandshakePacketHandler(function() : void{
|
||||
$this->onLoginSuccess();
|
||||
}));
|
||||
$this->logger->debug("Enabled encryption");
|
||||
}));
|
||||
}else{
|
||||
@ -557,7 +559,7 @@ class NetworkSession{
|
||||
}
|
||||
}
|
||||
|
||||
public function onLoginSuccess() : void{
|
||||
private function onLoginSuccess() : void{
|
||||
$this->loggedIn = true;
|
||||
|
||||
$this->sendDataPacket(PlayStatusPacket::create(PlayStatusPacket::LOGIN_SUCCESS));
|
||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\handler;
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket;
|
||||
|
||||
/**
|
||||
@ -31,15 +30,21 @@ use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket;
|
||||
*/
|
||||
class HandshakePacketHandler extends PacketHandler{
|
||||
|
||||
/** @var NetworkSession */
|
||||
private $session;
|
||||
/**
|
||||
* @var \Closure
|
||||
* @phpstan-var \Closure() : void
|
||||
*/
|
||||
private $onHandshakeCompleted;
|
||||
|
||||
public function __construct(NetworkSession $session){
|
||||
$this->session = $session;
|
||||
/**
|
||||
* @phpstan-param \Closure() : void $onHandshakeCompleted
|
||||
*/
|
||||
public function __construct(\Closure $onHandshakeCompleted){
|
||||
$this->onHandshakeCompleted = $onHandshakeCompleted;
|
||||
}
|
||||
|
||||
public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{
|
||||
$this->session->onLoginSuccess();
|
||||
($this->onHandshakeCompleted)();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
69
src/world/biome/BiomeRegistry.php
Normal file
69
src/world/biome/BiomeRegistry.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?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\world\biome;
|
||||
|
||||
use pocketmine\block\utils\TreeType;
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
|
||||
final class BiomeRegistry{
|
||||
use SingletonTrait;
|
||||
|
||||
/**
|
||||
* @var Biome[]|\SplFixedArray
|
||||
* @phpstan-var \SplFixedArray<Biome>
|
||||
*/
|
||||
private $biomes;
|
||||
|
||||
public function __construct(){
|
||||
$this->biomes = new \SplFixedArray(Biome::MAX_BIOMES);
|
||||
|
||||
$this->register(Biome::OCEAN, new OceanBiome());
|
||||
$this->register(Biome::PLAINS, new PlainBiome());
|
||||
$this->register(Biome::DESERT, new DesertBiome());
|
||||
$this->register(Biome::MOUNTAINS, new MountainsBiome());
|
||||
$this->register(Biome::FOREST, new ForestBiome());
|
||||
$this->register(Biome::TAIGA, new TaigaBiome());
|
||||
$this->register(Biome::SWAMP, new SwampBiome());
|
||||
$this->register(Biome::RIVER, new RiverBiome());
|
||||
|
||||
$this->register(Biome::ICE_PLAINS, new IcePlainsBiome());
|
||||
|
||||
$this->register(Biome::SMALL_MOUNTAINS, new SmallMountainsBiome());
|
||||
|
||||
$this->register(Biome::BIRCH_FOREST, new ForestBiome(TreeType::BIRCH()));
|
||||
}
|
||||
|
||||
public function register(int $id, Biome $biome) : void{
|
||||
$this->biomes[$id] = $biome;
|
||||
$biome->setId($id);
|
||||
}
|
||||
|
||||
public function getBiome(int $id) : Biome{
|
||||
if($this->biomes[$id] === null){
|
||||
$this->register($id, new UnknownBiome());
|
||||
}
|
||||
|
||||
return $this->biomes[$id];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user