130 private const MAX_FORM_RESPONSE_SIZE = 10 * 1024;
131 private const MAX_FORM_RESPONSE_DEPTH = 2;
133 protected float $lastRightClickTime = 0.0;
136 protected ?
Vector3 $lastPlayerAuthInputPosition =
null;
137 protected ?
float $lastPlayerAuthInputYaw =
null;
138 protected ?
float $lastPlayerAuthInputPitch =
null;
139 protected ?
BitSet $lastPlayerAuthInputFlags =
null;
143 public bool $forceMoveSync =
false;
145 protected ?
string $lastRequestedFullSkinId =
null;
147 public function __construct(
153 public function handleText(
TextPacket $packet) :
bool{
154 if($packet->type === TextPacket::TYPE_CHAT){
155 return $this->player->chat($packet->message);
161 private function resolveOnOffInputFlags(
BitSet $inputFlags,
int $startFlag,
int $stopFlag) : ?
bool{
162 $enabled = $inputFlags->get($startFlag);
163 $disabled = $inputFlags->get($stopFlag);
164 if($enabled !== $disabled){
172 $rawPos = $packet->getPosition();
173 $rawYaw = $packet->getYaw();
174 $rawPitch = $packet->getPitch();
175 foreach([$rawPos->x, $rawPos->y, $rawPos->z, $rawYaw, $packet->getHeadYaw(), $rawPitch] as $float){
176 if(is_infinite($float) || is_nan($float)){
177 $this->session->getLogger()->debug(
"Invalid movement received, contains NAN/INF components");
182 if($rawYaw !== $this->lastPlayerAuthInputYaw || $rawPitch !== $this->lastPlayerAuthInputPitch){
183 $this->lastPlayerAuthInputYaw = $rawYaw;
184 $this->lastPlayerAuthInputPitch = $rawPitch;
186 $yaw = fmod($rawYaw, 360);
187 $pitch = fmod($rawPitch, 360);
192 $this->player->setRotation($yaw, $pitch);
195 $hasMoved = $this->lastPlayerAuthInputPosition ===
null || !$this->lastPlayerAuthInputPosition->equals($rawPos);
196 $newPos = $rawPos->subtract(0, 1.62, 0)->round(4);
198 if($this->forceMoveSync && $hasMoved){
199 $curPos = $this->player->getLocation();
201 if($newPos->distanceSquared($curPos) > 1){
202 $this->session->getLogger()->debug(
"Got outdated pre-teleport movement, received " . $newPos .
", expected " . $curPos);
208 $this->forceMoveSync =
false;
211 $inputFlags = $packet->getInputFlags();
212 if($this->lastPlayerAuthInputFlags ===
null || !$inputFlags->equals($this->lastPlayerAuthInputFlags)){
213 $this->lastPlayerAuthInputFlags = $inputFlags;
217 $sneaking = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SNEAKING, PlayerAuthInputFlags::STOP_SNEAKING);
218 $sprinting = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SPRINTING, PlayerAuthInputFlags::STOP_SPRINTING);
219 $swimming = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SWIMMING, PlayerAuthInputFlags::STOP_SWIMMING);
220 $gliding = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_GLIDING, PlayerAuthInputFlags::STOP_GLIDING);
221 $flying = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_FLYING, PlayerAuthInputFlags::STOP_FLYING);
223 (!$this->player->toggleSneak($sneaking ?? $this->player->isSneaking(), $sneakPressed)) |
224 ($sprinting !==
null && !$this->player->toggleSprint($sprinting)) |
225 ($swimming !==
null && !$this->player->toggleSwim($swimming)) |
226 ($gliding !==
null && !$this->player->toggleGlide($gliding)) |
227 ($flying !==
null && !$this->player->toggleFlight($flying));
228 if((
bool) $mismatch){
229 $this->player->sendData([$this->player]);
233 $this->player->jump();
236 $this->player->missSwing();
240 if(!$this->forceMoveSync && $hasMoved){
241 $this->lastPlayerAuthInputPosition = $rawPos;
243 $this->player->handleMovement($newPos);
246 $packetHandled =
true;
248 $useItemTransaction = $packet->getItemInteractionData();
249 if($useItemTransaction !==
null){
250 if(count($useItemTransaction->getTransactionData()->getActions()) > 100){
254 $this->inventoryManager->setCurrentItemStackRequestId($useItemTransaction->getRequestId());
255 $this->inventoryManager->addRawPredictedSlotChanges($useItemTransaction->getTransactionData()->getActions());
256 if(!$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
257 $packetHandled =
false;
258 $this->session->getLogger()->debug(
"Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() .
")");
260 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
262 $this->inventoryManager->setCurrentItemStackRequestId(
null);
265 $itemStackRequest = $packet->getItemStackRequest();
266 $itemStackResponseBuilder = $itemStackRequest !==
null ? $this->handleSingleItemStackRequest($itemStackRequest) :
null;
270 $blockActions = $packet->getBlockActions();
271 if($blockActions !==
null){
272 if(count($blockActions) > 100){
275 foreach(Utils::promoteKeys($blockActions) as $k => $blockAction){
276 $actionHandled =
false;
278 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(),
new BlockPosition(0, 0, 0), 0);
280 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), $blockAction->getBlockPosition(), $blockAction->getFace());
284 $packetHandled =
false;
285 $this->session->getLogger()->debug(
"Unhandled player block action at offset $k in PlayerAuthInputPacket");
290 if($itemStackRequest !==
null){
291 $itemStackResponse = $itemStackResponseBuilder?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $itemStackRequest->getRequestId());
295 return $packetHandled;
301 if(count($packet->trData->getActions()) > 50){
304 if(count($packet->requestChangedSlots) > 10){
308 $this->inventoryManager->setCurrentItemStackRequestId($packet->requestId);
309 $this->inventoryManager->addRawPredictedSlotChanges($packet->trData->getActions());
312 $result = $this->handleNormalTransaction($packet->trData, $packet->requestId);
314 $this->session->getLogger()->debug(
"Mismatch transaction received");
315 $this->inventoryManager->requestSyncAll();
318 $result = $this->handleUseItemTransaction($packet->trData);
320 $result = $this->handleUseItemOnEntityTransaction($packet->trData);
322 $result = $this->handleReleaseItemTransaction($packet->trData);
325 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
331 foreach($packet->requestChangedSlots as $containerInfo){
332 foreach($containerInfo->getChangedSlotIndexes() as $netSlot){
334 $inventoryAndSlot = $this->inventoryManager->locateWindowAndSlot($windowId, $slot);
335 if($inventoryAndSlot !==
null){
336 $this->inventoryManager->requestSyncSlot($inventoryAndSlot[0], $inventoryAndSlot[1]);
341 $this->inventoryManager->setCurrentItemStackRequestId(
null);
345 private function executeInventoryTransaction(
InventoryTransaction $transaction,
int $requestId) :
bool{
346 $this->player->setUsingItem(
false);
348 $this->inventoryManager->setCurrentItemStackRequestId($requestId);
349 $this->inventoryManager->addTransactionPredictedSlotChanges($transaction);
353 $this->inventoryManager->requestSyncAll();
354 $logger = $this->session->getLogger();
355 $logger->debug(
"Invalid inventory transaction $requestId: " . $e->getMessage());
359 $this->session->getLogger()->debug(
"Inventory transaction $requestId cancelled by a plugin");
363 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
364 $this->inventoryManager->setCurrentItemStackRequestId(
null);
370 private function handleNormalTransaction(
NormalTransactionData $data,
int $itemStackRequestId) :
bool{
377 if($actionCount > 2){
378 if($actionCount > 5){
384 $this->session->getLogger()->debug(
"Ignoring normal inventory transaction with $actionCount actions (drop-item should have exactly 2 actions)");
389 $clientItemStack =
null;
390 $droppedCount =
null;
392 foreach($data->
getActions() as $networkInventoryAction){
393 if($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_WORLD && $networkInventoryAction->inventorySlot === NetworkInventoryAction::ACTION_MAGIC_SLOT_DROP_ITEM){
394 $droppedCount = $networkInventoryAction->newItem->getItemStack()->getCount();
395 if($droppedCount <= 0){
398 }elseif($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER && $networkInventoryAction->windowId === ContainerIds::INVENTORY){
400 $sourceSlot = $networkInventoryAction->inventorySlot;
401 $clientItemStack = $networkInventoryAction->oldItem->getItemStack();
403 $this->session->getLogger()->debug(
"Unexpected inventory action type $networkInventoryAction->sourceType in drop item transaction");
407 if($sourceSlot ===
null || $clientItemStack ===
null || $droppedCount ===
null){
408 $this->session->getLogger()->debug(
"Missing information in drop item transaction, need source slot, client item stack and dropped count");
412 $inventory = $this->player->getInventory();
414 if(!$inventory->slotExists($sourceSlot)){
418 $sourceSlotItem = $inventory->getItem($sourceSlot);
419 if($sourceSlotItem->getCount() < $droppedCount){
422 $serverItemStack = $this->session->getTypeConverter()->coreItemStackToNet($sourceSlotItem);
426 $serverItemStack->getId() !== $clientItemStack->getId() ||
427 $serverItemStack->getMeta() !== $clientItemStack->getMeta() ||
428 $serverItemStack->getCount() !== $clientItemStack->getCount() ||
429 $serverItemStack->getBlockRuntimeId() !== $clientItemStack->getBlockRuntimeId()
439 $droppedItem = $sourceSlotItem->pop($droppedCount);
442 $window = $this->inventoryManager->getInventoryWindow($inventory) ??
throw new AssumptionFailedError(
"This should never happen");
443 $builder->getActionBuilder($window)->setItem($sourceSlot, $sourceSlotItem);
447 return $this->executeInventoryTransaction($transaction, $itemStackRequestId);
451 $this->player->selectHotbarSlot($data->getHotbarSlot());
453 switch($data->getActionType()){
454 case UseItemTransactionData::ACTION_CLICK_BLOCK:
456 $clickPos = $data->getClickPosition();
457 $spamBug = ($this->lastRightClickData !==
null &&
458 microtime(
true) - $this->lastRightClickTime < 0.1 &&
459 $this->lastRightClickData->getPlayerPosition()->distanceSquared($data->getPlayerPosition()) < 0.00001 &&
460 $this->lastRightClickData->getBlockPosition()->equals($data->getBlockPosition()) &&
461 $this->lastRightClickData->getClickPosition()->distanceSquared($clickPos) < 0.00001
464 $this->lastRightClickData = $data;
465 $this->lastRightClickTime = microtime(
true);
471 $face = self::deserializeFacing($data->getFace());
473 $blockPos = $data->getBlockPosition();
474 $vBlockPos =
new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
475 $this->player->interactBlock($vBlockPos, $face, $clickPos);
476 if($data->getClientInteractPrediction() === PredictedResult::SUCCESS){
484 $syncAdjacentFace =
null;
485 if($data->getItemInHand()->getItemStack()->getBlockRuntimeId() === ItemTranslator::NO_BLOCK_RUNTIME_ID){
486 $this->session->getLogger()->debug(
"Placing held item might place multiple blocks client-side; doing full adjacent sync");
487 $syncAdjacentFace = $face;
489 $this->syncBlocksNearby($vBlockPos, $syncAdjacentFace);
492 case UseItemTransactionData::ACTION_CLICK_AIR:
493 if($this->player->isUsingItem()){
494 if(!$this->player->consumeHeldItem()){
495 $hungerAttr = $this->player->getAttributeMap()->get(Attribute::HUNGER) ??
throw new AssumptionFailedError();
496 $hungerAttr->markSynchronized(
false);
501 $this->player->setUsingItem(
false);
504 $this->player->useHeldItem();
514 private static function deserializeFacing(
int $facing) :
Facing{
516 $case = Facing::tryFrom($facing);
526 private function syncBlocksNearby(
Vector3 $blockPos, ?
Facing $face) :
void{
527 if($blockPos->distanceSquared($this->player->getLocation()) < 10000){
530 $sidePos = $blockPos->
getSide($face);
533 array_push($blocks, ...$sidePos->sidesArray());
535 $blocks[] = $blockPos;
537 foreach($this->player->getWorld()->createBlockUpdatePackets($blocks) as $packet){
538 $this->session->sendDataPacket($packet);
544 $target = $this->player->getWorld()->getEntity($data->getActorRuntimeId());
547 if($target ===
null || $target->isFlaggedForDespawn()){
551 $this->player->selectHotbarSlot($data->getHotbarSlot());
553 switch($data->getActionType()){
554 case UseItemOnEntityTransactionData::ACTION_INTERACT:
555 $this->player->interactEntity($target, $data->getClickPosition());
557 case UseItemOnEntityTransactionData::ACTION_ATTACK:
558 $this->player->attackEntity($target);
566 $this->player->selectHotbarSlot($data->getHotbarSlot());
568 if($data->getActionType() === ReleaseItemTransactionData::ACTION_RELEASE){
569 $this->player->releaseHeldItem();
592 $transaction = $executor->generateInventoryTransaction();
593 if($transaction !==
null){
594 $result = $this->executeInventoryTransaction($transaction, $request->getRequestId());
600 $this->session->getLogger()->debug(
"ItemStackRequest #" . $request->getRequestId() .
" failed: " . $e->getMessage());
601 $this->session->getLogger()->debug(implode(
"\n", Utils::printableExceptionInfo($e)));
602 $this->inventoryManager->requestSyncAll();
605 return $result ? $executor->getItemStackResponseBuilder() :
null;
610 if(count($packet->getRequests()) > 80){
614 foreach($packet->getRequests() as $request){
615 $responses[] = $this->handleSingleItemStackRequest($request)?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $request->getRequestId());
624 if($packet->windowId === ContainerIds::OFFHAND){
627 if($packet->windowId === ContainerIds::INVENTORY){
628 $this->inventoryManager->onClientSelectHotbarSlot($packet->hotbarSlot);
629 if(!$this->player->selectHotbarSlot($packet->hotbarSlot)){
630 $this->inventoryManager->syncSelectedHotbarSlot();
638 if($packet->action === InteractPacket::ACTION_MOUSEOVER){
646 $target = $this->player->getWorld()->getEntity($packet->targetActorRuntimeId);
647 if($target ===
null){
650 if($packet->action === InteractPacket::ACTION_OPEN_INVENTORY && $target === $this->player){
651 $this->inventoryManager->onClientOpenMainInventory();
658 return $this->player->pickBlock(
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ()), $packet->addUserData);
662 return $this->player->pickEntity($packet->actorUniqueId);
666 return $this->handlePlayerActionFromData($packet->action, $packet->blockPosition, $packet->face);
669 private function handlePlayerActionFromData(
int $action,
BlockPosition $blockPosition,
int $extraData) :
bool{
670 $pos =
new Vector3($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ());
673 case PlayerAction::START_BREAK:
674 case PlayerAction::CONTINUE_DESTROY_BLOCK:
675 $face = self::deserializeFacing($extraData);
676 if($this->lastBlockAttacked !==
null && $blockPosition->equals($this->lastBlockAttacked)){
681 $this->session->getLogger()->debug(
"Ignoring PlayerAction $action on $pos because we were already destroying this block");
684 if(!$this->player->attackBlock($pos, $face)){
685 $this->syncBlocksNearby($pos, $face);
687 $this->lastBlockAttacked = $blockPosition;
691 case PlayerAction::ABORT_BREAK:
692 case PlayerAction::STOP_BREAK:
693 $this->player->stopBreakBlock($pos);
694 $this->lastBlockAttacked =
null;
696 case PlayerAction::START_SLEEPING:
699 case PlayerAction::STOP_SLEEPING:
700 $this->player->stopSleep();
702 case PlayerAction::CRACK_BREAK:
703 $face = self::deserializeFacing($extraData);
704 $this->player->continueBreakBlock($pos, $face);
705 $this->lastBlockAttacked = $blockPosition;
707 case PlayerAction::INTERACT_BLOCK:
709 case PlayerAction::CREATIVE_PLAYER_DESTROY_BLOCK:
712 case PlayerAction::PREDICT_DESTROY_BLOCK:
713 if(!$this->player->breakBlock($pos)){
714 $face = self::deserializeFacing($extraData);
715 $this->syncBlocksNearby($pos, $face);
717 $this->lastBlockAttacked =
null;
719 case PlayerAction::START_ITEM_USE_ON:
720 case PlayerAction::STOP_ITEM_USE_ON:
724 $this->session->getLogger()->debug(
"Unhandled/unknown player action type " . $action);
728 $this->player->setUsingItem(
false);
740 $this->inventoryManager->onClientRemoveWindow($packet->windowId);
748 $textTag = $nbt->
getTag($tagName);
750 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textTag) .
" for tag \"$tagName\" in sign update data");
752 $textBlobTag = $textTag->getTag(Sign::TAG_TEXT_BLOB);
754 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textBlobTag) .
" for tag \"" . Sign::TAG_TEXT_BLOB .
"\" in sign update data");
758 $text = SignText::fromBlob($textBlobTag->getValue());
759 }
catch(\InvalidArgumentException $e){
760 throw PacketHandlingException::wrap($e,
"Invalid sign text update");
763 $oldText = $block->getFaceText($frontFace);
764 if($text->getLines() === $oldText->getLines()){
770 foreach($this->player->getWorld()->createBlockUpdatePackets([$pos]) as $updatePacket){
771 $this->session->sendDataPacket($updatePacket);
776 }
catch(\UnexpectedValueException $e){
777 throw PacketHandlingException::wrap($e);
782 $pos =
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ());
783 if($pos->distanceSquared($this->player->getLocation()) > 10000){
787 $block = $this->player->getLocation()->getWorld()->getBlock($pos);
788 $nbt = $packet->nbt->getRoot();
792 if(!$this->updateSignText($nbt, Sign::TAG_FRONT_TEXT,
true, $block, $pos)){
794 $this->updateSignText($nbt, Sign::TAG_BACK_TEXT,
false, $block, $pos);
804 $gameMode = $this->session->getTypeConverter()->protocolGameModeToCore($packet->gamemode);
805 if($gameMode !== $this->player->getGamemode()){
807 $this->session->syncGameMode($this->player->getGamemode(),
true);
813 $this->player->setViewDistance($packet->radius);
819 if(str_starts_with($packet->command,
'/')){
820 $this->player->chat($packet->command);
827 if($packet->skin->getFullSkinId() === $this->lastRequestedFullSkinId){
830 $this->session->getLogger()->debug(
"Refused duplicate skin change request");
833 $this->lastRequestedFullSkinId = $packet->skin->getFullSkinId();
835 $this->session->getLogger()->debug(
"Processing skin change request");
837 $skin = $this->session->getTypeConverter()->getSkinAdapter()->fromSkinData($packet->skin);
839 throw PacketHandlingException::wrap($e,
"Invalid skin in PlayerSkinPacket");
841 return $this->player->changeSkin($skin, $packet->newSkinName, $packet->oldSkinName);
847 private function checkBookText(
string $string,
string $fieldName,
int $softLimit,
int $hardLimit,
bool &$cancel) :
string{
848 if(strlen($string) > $hardLimit){
849 throw new PacketHandlingException(sprintf(
"Book %s must be at most %d bytes, but have %d bytes", $fieldName, $hardLimit, strlen($string)));
852 $result = TextFormat::clean($string,
false);
854 if(strlen($result) > $softLimit * 4 || mb_strlen($result,
'UTF-8') > $softLimit){
856 $this->session->getLogger()->debug(
"Cancelled book edit due to $fieldName exceeded soft limit of $softLimit chars");
863 $inventory = $this->player->getInventory();
864 if(!$inventory->slotExists($packet->inventorySlot)){
868 $oldBook = $inventory->getItem($packet->inventorySlot);
873 $newBook = clone $oldBook;
876 switch($packet->type){
877 case BookEditPacket::TYPE_REPLACE_PAGE:
878 $text = self::checkBookText($packet->text,
"page text", 256, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
879 $newBook->setPageText($packet->pageNumber, $text);
880 $modifiedPages[] = $packet->pageNumber;
882 case BookEditPacket::TYPE_ADD_PAGE:
883 if(!$newBook->pageExists($packet->pageNumber)){
888 $text = self::checkBookText($packet->text,
"page text", 256, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
889 $newBook->insertPage($packet->pageNumber, $text);
890 $modifiedPages[] = $packet->pageNumber;
892 case BookEditPacket::TYPE_DELETE_PAGE:
893 if(!$newBook->pageExists($packet->pageNumber)){
896 $newBook->deletePage($packet->pageNumber);
897 $modifiedPages[] = $packet->pageNumber;
899 case BookEditPacket::TYPE_SWAP_PAGES:
900 if(!$newBook->pageExists($packet->pageNumber) || !$newBook->pageExists($packet->secondaryPageNumber)){
902 $newBook->addPage(max($packet->pageNumber, $packet->secondaryPageNumber));
904 $newBook->swapPages($packet->pageNumber, $packet->secondaryPageNumber);
905 $modifiedPages = [$packet->pageNumber, $packet->secondaryPageNumber];
907 case BookEditPacket::TYPE_SIGN_BOOK:
908 $title = self::checkBookText($packet->title,
"title", 16, Limits::INT16_MAX, $cancel);
910 $author = self::checkBookText($packet->author,
"author", 256, Limits::INT16_MAX, $cancel);
912 $newBook = VanillaItems::WRITTEN_BOOK()
913 ->setPages($oldBook->getPages())
916 ->setGeneration(WrittenBook::GENERATION_ORIGINAL);
923 $action = match($packet->type){
924 BookEditPacket::TYPE_REPLACE_PAGE => PlayerEditBookEvent::ACTION_REPLACE_PAGE,
925 BookEditPacket::TYPE_ADD_PAGE => PlayerEditBookEvent::ACTION_ADD_PAGE,
926 BookEditPacket::TYPE_DELETE_PAGE => PlayerEditBookEvent::ACTION_DELETE_PAGE,
927 BookEditPacket::TYPE_SWAP_PAGES => PlayerEditBookEvent::ACTION_SWAP_PAGES,
928 BookEditPacket::TYPE_SIGN_BOOK => PlayerEditBookEvent::ACTION_SIGN_BOOK,
936 $oldPageCount = count($oldBook->getPages());
937 $newPageCount = count($newBook->getPages());
938 if(($newPageCount > $oldPageCount && $newPageCount > 50)){
939 $this->session->getLogger()->debug(
"Cancelled book edit due to adding too many pages (new page count would be $newPageCount)");
943 $event =
new PlayerEditBookEvent($this->player, $oldBook, $newBook, $action, $modifiedPages);
949 if($event->isCancelled()){
953 $this->player->getInventory()->setItem($packet->inventorySlot, $event->getNewBook());
959 if($packet->cancelReason !==
null){
961 return $this->player->onFormSubmit($packet->formId,
null);
962 }elseif($packet->formData !==
null){
963 if(strlen($packet->formData) > self::MAX_FORM_RESPONSE_SIZE){
964 throw new PacketHandlingException(
"Form response data too large, refusing to decode (received" . strlen($packet->formData) .
" bytes, max " . self::MAX_FORM_RESPONSE_SIZE .
" bytes)");
966 if(!$this->player->hasPendingForm($packet->formId)){
967 $this->session->getLogger()->debug(
"Got unexpected response for form $packet->formId");
971 $responseData = json_decode($packet->formData,
true, self::MAX_FORM_RESPONSE_DEPTH, JSON_THROW_ON_ERROR);
972 }
catch(\JsonException $e){
973 throw PacketHandlingException::wrap($e,
"Failed to decode form response data");
975 return $this->player->onFormSubmit($packet->formId, $responseData);
977 throw new PacketHandlingException(
"Expected either formData or cancelReason to be set in ModalFormResponsePacket");
982 $pos = $packet->blockPosition;
983 $chunkX = $pos->getX() >> Chunk::COORD_BIT_SIZE;
984 $chunkZ = $pos->getZ() >> Chunk::COORD_BIT_SIZE;
985 $world = $this->player->getWorld();
986 if(!$world->isChunkLoaded($chunkX, $chunkZ) || $world->isChunkLocked($chunkX, $chunkZ)){
990 $lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ());
991 if($lectern instanceof
Lectern && $this->player->canInteract($lectern->getPosition(), 15)){
992 if(!$lectern->onPageTurn($packet->page)){
993 $this->syncBlocksNearby($lectern->getPosition(),
null);
1001 public function handleEmote(
EmotePacket $packet) :
bool{
1002 $this->player->emote($packet->getEmoteId());