Skip to content

Commit

Permalink
Added compatibility for PocketMine-MP 5.0.0 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierLeon9966 authored Jun 5, 2023
1 parent 02d7680 commit 041af8b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: FakePlayer
main: muqsit\fakeplayer\Loader
api: 4.21.1
api: 5.0.0
version: 0.2.4

permissions:
Expand Down
6 changes: 3 additions & 3 deletions src/muqsit/fakeplayer/DefaultFakePlayerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use muqsit\fakeplayer\listener\FakePlayerListener;
use muqsit\fakeplayer\network\FakePlayerNetworkSession;
use muqsit\fakeplayer\network\listener\ClosureFakePlayerPacketListener;
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\ChangeDimensionPacket;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
Expand Down Expand Up @@ -39,7 +39,7 @@ public function onPlayerAdd(Player $player) : void{
$this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(static function() use($session, $entity_runtime_id) : void{
if($session->isConnected()){
$packet = SetLocalPlayerAsInitializedPacket::create($entity_runtime_id);
$serializer = PacketSerializer::encoder(new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary()));
$serializer = PacketSerializer::encoder(new PacketSerializerContext(TypeConverter::getInstance()->getItemTypeDictionary()));
$packet->encode($serializer);
$session->handleDataPacket($packet, $serializer->getBuffer());
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public function onPlayerAdd(Player $player) : void{
0
);

$serializer = PacketSerializer::encoder(new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary()));
$serializer = PacketSerializer::encoder(new PacketSerializerContext(TypeConverter::getInstance()->getItemTypeDictionary()));
$packet->encode($serializer);
$session->handleDataPacket($packet, $serializer->getBuffer());
}
Expand Down
4 changes: 2 additions & 2 deletions src/muqsit/fakeplayer/FakePlayerCommandExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
Expand All @@ -31,7 +31,7 @@ public function __construct(
){}

private function sendServerPacket(Player $sender, Packet $packet) : void{
$context = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
$context = new PacketSerializerContext(TypeConverter::getInstance()->getItemTypeDictionary());
$serializer = PacketSerializer::encoder($context);
$packet->encode($serializer);
$sender->getNetworkSession()->handleDataPacket($packet, $serializer->getBuffer());
Expand Down
8 changes: 5 additions & 3 deletions src/muqsit/fakeplayer/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\network\mcpe\compression\ZlibCompressor;
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
Expand Down Expand Up @@ -137,9 +137,10 @@ public function getFakePlayer(Player $player) : ?FakePlayer{
public function addPlayer(FakePlayerInfo $info) : Promise{
$server = $this->getServer();
$network = $server->getNetwork();
$packet_serializer_context = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
$type_converter = TypeConverter::getInstance();
$packet_serializer_context = new PacketSerializerContext($type_converter->getItemTypeDictionary());
$packet_broadcaster = new StandardPacketBroadcaster($this->getServer(), $packet_serializer_context);
$entity_event_broadcaster = new StandardEntityEventBroadcaster($packet_broadcaster);
$entity_event_broadcaster = new StandardEntityEventBroadcaster($packet_broadcaster, $type_converter);

$internal_resolver = new PromiseResolver();
$session = new FakePlayerNetworkSession(
Expand All @@ -151,6 +152,7 @@ public function addPlayer(FakePlayerInfo $info) : Promise{
$packet_broadcaster,
$entity_event_broadcaster,
ZlibCompressor::getInstance(),
$type_converter,
$server->getIp(),
$server->getPort(),
$internal_resolver
Expand Down
4 changes: 3 additions & 1 deletion src/muqsit/fakeplayer/network/FakePlayerNetworkSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use muqsit\fakeplayer\network\listener\FakePlayerPacketListener;
use muqsit\fakeplayer\network\listener\FakePlayerSpecificPacketListener;
use pocketmine\network\mcpe\compression\Compressor;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\EntityEventBroadcaster;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\PacketBroadcaster;
Expand Down Expand Up @@ -53,11 +54,12 @@ public function __construct(
PacketBroadcaster $broadcaster,
EntityEventBroadcaster $entityEventBroadcaster,
Compressor $compressor,
TypeConverter $typeConverter,
string $ip,
int $port,
PromiseResolver $player_add_resolver
){
parent::__construct($server, $manager, $packetPool, $packetSerializerContext, $sender, $broadcaster, $entityEventBroadcaster, $compressor, $ip, $port);
parent::__construct($server, $manager, $packetPool, $packetSerializerContext, $sender, $broadcaster, $entityEventBroadcaster, $compressor, $typeConverter, $ip, $port);
$this->player_add_resolver = $player_add_resolver;

// do not store the resolver eternally
Expand Down

0 comments on commit 041af8b

Please sign in to comment.