130 private const MAX_FORM_RESPONSE_SIZE = 10 * 1024;
131 private const MAX_FORM_RESPONSE_DEPTH = 2;
136 private const PAGE_LENGTH_SOFT_LIMIT_CHARS = 512;
138 protected float $lastRightClickTime = 0.0;
141 protected ?
Vector3 $lastPlayerAuthInputPosition =
null;
142 protected ?
float $lastPlayerAuthInputYaw =
null;
143 protected ?
float $lastPlayerAuthInputPitch =
null;
144 protected ?
BitSet $lastPlayerAuthInputFlags =
null;
148 public bool $forceMoveSync =
false;
150 protected ?
string $lastRequestedFullSkinId =
null;
152 public function __construct(
158 public function handleText(
TextPacket $packet) :
bool{
159 if($packet->type === TextPacket::TYPE_CHAT){
160 return $this->player->chat($packet->message);
166 private function resolveOnOffInputFlags(
BitSet $inputFlags,
int $startFlag,
int $stopFlag) : ?
bool{
167 $enabled = $inputFlags->get($startFlag);
168 $disabled = $inputFlags->get($stopFlag);
169 if($enabled !== $disabled){
177 $rawPos = $packet->getPosition();
178 $rawYaw = $packet->getYaw();
179 $rawPitch = $packet->getPitch();
180 foreach([$rawPos->x, $rawPos->y, $rawPos->z, $rawYaw, $packet->getHeadYaw(), $rawPitch] as $float){
181 if(is_infinite($float) || is_nan($float)){
182 $this->session->getLogger()->debug(
"Invalid movement received, contains NAN/INF components");
187 if($rawYaw !== $this->lastPlayerAuthInputYaw || $rawPitch !== $this->lastPlayerAuthInputPitch){
188 $this->lastPlayerAuthInputYaw = $rawYaw;
189 $this->lastPlayerAuthInputPitch = $rawPitch;
191 $yaw = fmod($rawYaw, 360);
192 $pitch = fmod($rawPitch, 360);
197 $this->player->setRotation($yaw, $pitch);
200 $hasMoved = $this->lastPlayerAuthInputPosition ===
null || !$this->lastPlayerAuthInputPosition->equals($rawPos);
201 $newPos = $rawPos->subtract(0, 1.62, 0)->round(4);
203 if($this->forceMoveSync && $hasMoved){
204 $curPos = $this->player->getLocation();
206 if($newPos->distanceSquared($curPos) > 1){
207 $this->session->getLogger()->debug(
"Got outdated pre-teleport movement, received " . $newPos .
", expected " . $curPos);
213 $this->forceMoveSync =
false;
216 $inputFlags = $packet->getInputFlags();
217 if($this->lastPlayerAuthInputFlags ===
null || !$inputFlags->equals($this->lastPlayerAuthInputFlags)){
218 $this->lastPlayerAuthInputFlags = $inputFlags;
222 $sneaking = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SNEAKING, PlayerAuthInputFlags::STOP_SNEAKING);
223 $sprinting = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SPRINTING, PlayerAuthInputFlags::STOP_SPRINTING);
224 $swimming = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SWIMMING, PlayerAuthInputFlags::STOP_SWIMMING);
225 $gliding = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_GLIDING, PlayerAuthInputFlags::STOP_GLIDING);
226 $flying = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_FLYING, PlayerAuthInputFlags::STOP_FLYING);
228 (!$this->player->toggleSneak($sneaking ?? $this->player->isSneaking(), $sneakPressed)) |
229 ($sprinting !==
null && !$this->player->toggleSprint($sprinting)) |
230 ($swimming !==
null && !$this->player->toggleSwim($swimming)) |
231 ($gliding !==
null && !$this->player->toggleGlide($gliding)) |
232 ($flying !==
null && !$this->player->toggleFlight($flying));
233 if((
bool) $mismatch){
234 $this->player->sendData([$this->player]);
238 $this->player->jump();
241 $this->player->missSwing();
245 if(!$this->forceMoveSync && $hasMoved){
246 $this->lastPlayerAuthInputPosition = $rawPos;
248 $this->player->handleMovement($newPos);
251 $packetHandled =
true;
253 $useItemTransaction = $packet->getItemInteractionData();
254 if($useItemTransaction !==
null){
255 if(count($useItemTransaction->getTransactionData()->getActions()) > 100){
259 $this->inventoryManager->setCurrentItemStackRequestId($useItemTransaction->getRequestId());
260 $this->inventoryManager->addRawPredictedSlotChanges($useItemTransaction->getTransactionData()->getActions());
261 if(!$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
262 $packetHandled =
false;
263 $this->session->getLogger()->debug(
"Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() .
")");
265 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
267 $this->inventoryManager->setCurrentItemStackRequestId(
null);
270 $itemStackRequest = $packet->getItemStackRequest();
271 $itemStackResponseBuilder = $itemStackRequest !==
null ? $this->handleSingleItemStackRequest($itemStackRequest) :
null;
275 $blockActions = $packet->getBlockActions();
276 if($blockActions !==
null){
277 if(count($blockActions) > 100){
280 foreach(Utils::promoteKeys($blockActions) as $k => $blockAction){
281 $actionHandled =
false;
283 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(),
new BlockPosition(0, 0, 0), 0);
285 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), $blockAction->getBlockPosition(), $blockAction->getFace());
289 $packetHandled =
false;
290 $this->session->getLogger()->debug(
"Unhandled player block action at offset $k in PlayerAuthInputPacket");
295 if($itemStackRequest !==
null){
296 $itemStackResponse = $itemStackResponseBuilder?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $itemStackRequest->getRequestId());
300 return $packetHandled;
306 if(count($packet->trData->getActions()) > 50){
309 if(count($packet->requestChangedSlots) > 10){
313 $this->inventoryManager->setCurrentItemStackRequestId($packet->requestId);
314 $this->inventoryManager->addRawPredictedSlotChanges($packet->trData->getActions());
317 $result = $this->handleNormalTransaction($packet->trData, $packet->requestId);
319 $this->session->getLogger()->debug(
"Mismatch transaction received");
320 $this->inventoryManager->requestSyncAll();
323 $result = $this->handleUseItemTransaction($packet->trData);
325 $result = $this->handleUseItemOnEntityTransaction($packet->trData);
327 $result = $this->handleReleaseItemTransaction($packet->trData);
330 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
336 foreach($packet->requestChangedSlots as $containerInfo){
337 foreach($containerInfo->getChangedSlotIndexes() as $netSlot){
339 $inventoryAndSlot = $this->inventoryManager->locateWindowAndSlot($windowId, $slot);
340 if($inventoryAndSlot !==
null){
341 $this->inventoryManager->requestSyncSlot($inventoryAndSlot[0], $inventoryAndSlot[1]);
346 $this->inventoryManager->setCurrentItemStackRequestId(
null);
350 private function executeInventoryTransaction(
InventoryTransaction $transaction,
int $requestId) :
bool{
351 $this->player->setUsingItem(
false);
353 $this->inventoryManager->setCurrentItemStackRequestId($requestId);
354 $this->inventoryManager->addTransactionPredictedSlotChanges($transaction);
358 $this->inventoryManager->requestSyncAll();
359 $logger = $this->session->getLogger();
360 $logger->debug(
"Invalid inventory transaction $requestId: " . $e->getMessage());
364 $this->session->getLogger()->debug(
"Inventory transaction $requestId cancelled by a plugin");
368 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
369 $this->inventoryManager->setCurrentItemStackRequestId(
null);
375 private function handleNormalTransaction(
NormalTransactionData $data,
int $itemStackRequestId) :
bool{
382 if($actionCount > 2){
383 if($actionCount > 5){
389 $this->session->getLogger()->debug(
"Ignoring normal inventory transaction with $actionCount actions (drop-item should have exactly 2 actions)");
394 $clientItemStack =
null;
395 $droppedCount =
null;
397 foreach($data->
getActions() as $networkInventoryAction){
398 if($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_WORLD && $networkInventoryAction->inventorySlot === NetworkInventoryAction::ACTION_MAGIC_SLOT_DROP_ITEM){
399 $droppedCount = $networkInventoryAction->newItem->getItemStack()->getCount();
400 if($droppedCount <= 0){
403 }elseif($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER && $networkInventoryAction->windowId === ContainerIds::INVENTORY){
405 $sourceSlot = $networkInventoryAction->inventorySlot;
406 $clientItemStack = $networkInventoryAction->oldItem->getItemStack();
408 $this->session->getLogger()->debug(
"Unexpected inventory action type $networkInventoryAction->sourceType in drop item transaction");
412 if($sourceSlot ===
null || $clientItemStack ===
null || $droppedCount ===
null){
413 $this->session->getLogger()->debug(
"Missing information in drop item transaction, need source slot, client item stack and dropped count");
417 $inventory = $this->player->getInventory();
419 if(!$inventory->slotExists($sourceSlot)){
423 $sourceSlotItem = $inventory->getItem($sourceSlot);
424 if($sourceSlotItem->getCount() < $droppedCount){
427 $serverItemStack = $this->session->getTypeConverter()->coreItemStackToNet($sourceSlotItem);
431 $serverItemStack->getId() !== $clientItemStack->getId() ||
432 $serverItemStack->getMeta() !== $clientItemStack->getMeta() ||
433 $serverItemStack->getCount() !== $clientItemStack->getCount() ||
434 $serverItemStack->getBlockRuntimeId() !== $clientItemStack->getBlockRuntimeId()
444 $droppedItem = $sourceSlotItem->pop($droppedCount);
447 $window = $this->inventoryManager->getInventoryWindow($inventory) ??
throw new AssumptionFailedError(
"This should never happen");
448 $builder->getActionBuilder($window)->setItem($sourceSlot, $sourceSlotItem);
452 return $this->executeInventoryTransaction($transaction, $itemStackRequestId);
456 $this->player->selectHotbarSlot($data->getHotbarSlot());
458 switch($data->getActionType()){
459 case UseItemTransactionData::ACTION_CLICK_BLOCK:
461 $clickPos = $data->getClickPosition();
462 $spamBug = ($this->lastRightClickData !==
null &&
463 microtime(
true) - $this->lastRightClickTime < 0.1 &&
464 $this->lastRightClickData->getPlayerPosition()->distanceSquared($data->getPlayerPosition()) < 0.00001 &&
465 $this->lastRightClickData->getBlockPosition()->equals($data->getBlockPosition()) &&
466 $this->lastRightClickData->getClickPosition()->distanceSquared($clickPos) < 0.00001
469 $this->lastRightClickData = $data;
470 $this->lastRightClickTime = microtime(
true);
476 $face = self::deserializeFacing($data->getFace());
478 $blockPos = $data->getBlockPosition();
479 $vBlockPos =
new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
480 $this->player->interactBlock($vBlockPos, $face, $clickPos);
481 if($data->getClientInteractPrediction() === PredictedResult::SUCCESS){
489 $syncAdjacentFace =
null;
490 if($data->getItemInHand()->getItemStack()->getBlockRuntimeId() === ItemTranslator::NO_BLOCK_RUNTIME_ID){
491 $this->session->getLogger()->debug(
"Placing held item might place multiple blocks client-side; doing full adjacent sync");
492 $syncAdjacentFace = $face;
494 $this->syncBlocksNearby($vBlockPos, $syncAdjacentFace);
497 case UseItemTransactionData::ACTION_CLICK_AIR:
498 if($this->player->isUsingItem()){
499 if(!$this->player->consumeHeldItem()){
500 $hungerAttr = $this->player->getAttributeMap()->get(Attribute::HUNGER) ??
throw new AssumptionFailedError();
501 $hungerAttr->markSynchronized(
false);
506 $this->player->setUsingItem(
false);
509 $this->player->useHeldItem();
519 private static function deserializeFacing(
int $facing) :
Facing{
521 $case = Facing::tryFrom($facing);
531 private function syncBlocksNearby(
Vector3 $blockPos, ?
Facing $face) :
void{
532 if($blockPos->distanceSquared($this->player->getLocation()) < 10000){
535 $sidePos = $blockPos->
getSide($face);
538 array_push($blocks, ...$sidePos->sidesArray());
540 $blocks[] = $blockPos;
542 foreach($this->player->getWorld()->createBlockUpdatePackets($blocks) as $packet){
543 $this->session->sendDataPacket($packet);
549 $target = $this->player->getWorld()->getEntity($data->getActorRuntimeId());
552 if($target ===
null || $target->isFlaggedForDespawn()){
556 $this->player->selectHotbarSlot($data->getHotbarSlot());
558 switch($data->getActionType()){
559 case UseItemOnEntityTransactionData::ACTION_INTERACT:
560 $this->player->interactEntity($target, $data->getClickPosition());
562 case UseItemOnEntityTransactionData::ACTION_ATTACK:
563 $this->player->attackEntity($target);
571 $this->player->selectHotbarSlot($data->getHotbarSlot());
573 if($data->getActionType() === ReleaseItemTransactionData::ACTION_RELEASE){
574 $this->player->releaseHeldItem();
597 $transaction = $executor->generateInventoryTransaction();
598 if($transaction !==
null){
599 $result = $this->executeInventoryTransaction($transaction, $request->getRequestId());
605 $this->session->getLogger()->debug(
"ItemStackRequest #" . $request->getRequestId() .
" failed: " . $e->getMessage());
606 $this->session->getLogger()->debug(implode(
"\n", Utils::printableExceptionInfo($e)));
607 $this->inventoryManager->requestSyncAll();
610 return $result ? $executor->getItemStackResponseBuilder() :
null;
615 if(count($packet->getRequests()) > 80){
619 foreach($packet->getRequests() as $request){
620 $responses[] = $this->handleSingleItemStackRequest($request)?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $request->getRequestId());
629 if($packet->windowId === ContainerIds::OFFHAND){
632 if($packet->windowId === ContainerIds::INVENTORY){
633 $this->inventoryManager->onClientSelectHotbarSlot($packet->hotbarSlot);
634 if(!$this->player->selectHotbarSlot($packet->hotbarSlot)){
635 $this->inventoryManager->syncSelectedHotbarSlot();
643 if($packet->action === InteractPacket::ACTION_MOUSEOVER){
651 $target = $this->player->getWorld()->getEntity($packet->targetActorRuntimeId);
652 if($target ===
null){
655 if($packet->action === InteractPacket::ACTION_OPEN_INVENTORY && $target === $this->player){
656 $this->inventoryManager->onClientOpenMainInventory();
663 return $this->player->pickBlock(
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ()), $packet->addUserData);
667 return $this->player->pickEntity($packet->actorUniqueId);
671 return $this->handlePlayerActionFromData($packet->action, $packet->blockPosition, $packet->face);
674 private function handlePlayerActionFromData(
int $action,
BlockPosition $blockPosition,
int $extraData) :
bool{
675 $pos =
new Vector3($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ());
678 case PlayerAction::START_BREAK:
679 case PlayerAction::CONTINUE_DESTROY_BLOCK:
680 $face = self::deserializeFacing($extraData);
681 if($this->lastBlockAttacked !==
null && $blockPosition->equals($this->lastBlockAttacked)){
686 $this->session->getLogger()->debug(
"Ignoring PlayerAction $action on $pos because we were already destroying this block");
689 if(!$this->player->attackBlock($pos, $face)){
690 $this->syncBlocksNearby($pos, $face);
692 $this->lastBlockAttacked = $blockPosition;
696 case PlayerAction::ABORT_BREAK:
697 case PlayerAction::STOP_BREAK:
698 $this->player->stopBreakBlock($pos);
699 $this->lastBlockAttacked =
null;
701 case PlayerAction::START_SLEEPING:
704 case PlayerAction::STOP_SLEEPING:
705 $this->player->stopSleep();
707 case PlayerAction::CRACK_BREAK:
708 $face = self::deserializeFacing($extraData);
709 $this->player->continueBreakBlock($pos, $face);
710 $this->lastBlockAttacked = $blockPosition;
712 case PlayerAction::INTERACT_BLOCK:
714 case PlayerAction::CREATIVE_PLAYER_DESTROY_BLOCK:
717 case PlayerAction::PREDICT_DESTROY_BLOCK:
718 if(!$this->player->breakBlock($pos)){
719 $face = self::deserializeFacing($extraData);
720 $this->syncBlocksNearby($pos, $face);
722 $this->lastBlockAttacked =
null;
724 case PlayerAction::START_ITEM_USE_ON:
725 case PlayerAction::STOP_ITEM_USE_ON:
729 $this->session->getLogger()->debug(
"Unhandled/unknown player action type " . $action);
733 $this->player->setUsingItem(
false);
745 $this->inventoryManager->onClientRemoveWindow($packet->windowId);
753 $textTag = $nbt->
getTag($tagName);
755 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textTag) .
" for tag \"$tagName\" in sign update data");
757 $textBlobTag = $textTag->getTag(Sign::TAG_TEXT_BLOB);
759 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textBlobTag) .
" for tag \"" . Sign::TAG_TEXT_BLOB .
"\" in sign update data");
763 $text = SignText::fromBlob($textBlobTag->getValue());
764 }
catch(\InvalidArgumentException $e){
765 throw PacketHandlingException::wrap($e,
"Invalid sign text update");
768 $oldText = $block->getFaceText($frontFace);
769 if($text->getLines() === $oldText->getLines()){
775 foreach($this->player->getWorld()->createBlockUpdatePackets([$pos]) as $updatePacket){
776 $this->session->sendDataPacket($updatePacket);
781 }
catch(\UnexpectedValueException $e){
782 throw PacketHandlingException::wrap($e);
787 $pos =
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ());
788 if($pos->distanceSquared($this->player->getLocation()) > 10000){
792 $block = $this->player->getLocation()->getWorld()->getBlock($pos);
793 $nbt = $packet->nbt->getRoot();
797 if(!$this->updateSignText($nbt, Sign::TAG_FRONT_TEXT,
true, $block, $pos)){
799 $this->updateSignText($nbt, Sign::TAG_BACK_TEXT,
false, $block, $pos);
809 $gameMode = $this->session->getTypeConverter()->protocolGameModeToCore($packet->gamemode);
810 if($gameMode !== $this->player->getGamemode()){
812 $this->session->syncGameMode($this->player->getGamemode(),
true);
818 $this->player->setViewDistance($packet->radius);
824 if(str_starts_with($packet->command,
'/')){
825 $this->player->chat($packet->command);
832 if($packet->skin->getFullSkinId() === $this->lastRequestedFullSkinId){
835 $this->session->getLogger()->debug(
"Refused duplicate skin change request");
838 $this->lastRequestedFullSkinId = $packet->skin->getFullSkinId();
840 $this->session->getLogger()->debug(
"Processing skin change request");
842 $skin = $this->session->getTypeConverter()->getSkinAdapter()->fromSkinData($packet->skin);
844 throw PacketHandlingException::wrap($e,
"Invalid skin in PlayerSkinPacket");
846 return $this->player->changeSkin($skin, $packet->newSkinName, $packet->oldSkinName);
852 private function checkBookText(
string $string,
string $fieldName,
int $softLimit,
int $hardLimit,
bool &$cancel) :
string{
853 if(strlen($string) > $hardLimit){
854 throw new PacketHandlingException(sprintf(
"Book %s must be at most %d bytes, but have %d bytes", $fieldName, $hardLimit, strlen($string)));
857 $result = TextFormat::clean($string,
false);
859 if(strlen($result) > $softLimit * 4 || mb_strlen($result,
'UTF-8') > $softLimit){
861 $this->session->getLogger()->debug(
"Cancelled book edit due to $fieldName exceeded soft limit of $softLimit chars");
868 $inventory = $this->player->getInventory();
869 if(!$inventory->slotExists($packet->inventorySlot)){
873 $oldBook = $inventory->getItem($packet->inventorySlot);
878 $newBook = clone $oldBook;
881 switch($packet->type){
882 case BookEditPacket::TYPE_REPLACE_PAGE:
883 $text = self::checkBookText($packet->text,
"page text", self::PAGE_LENGTH_SOFT_LIMIT_CHARS, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
884 $newBook->setPageText($packet->pageNumber, $text);
885 $modifiedPages[] = $packet->pageNumber;
887 case BookEditPacket::TYPE_ADD_PAGE:
888 if(!$newBook->pageExists($packet->pageNumber)){
893 $text = self::checkBookText($packet->text,
"page text", self::PAGE_LENGTH_SOFT_LIMIT_CHARS, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
894 $newBook->insertPage($packet->pageNumber, $text);
895 $modifiedPages[] = $packet->pageNumber;
897 case BookEditPacket::TYPE_DELETE_PAGE:
898 if(!$newBook->pageExists($packet->pageNumber)){
901 $newBook->deletePage($packet->pageNumber);
902 $modifiedPages[] = $packet->pageNumber;
904 case BookEditPacket::TYPE_SWAP_PAGES:
905 if(!$newBook->pageExists($packet->pageNumber) || !$newBook->pageExists($packet->secondaryPageNumber)){
907 $newBook->addPage(max($packet->pageNumber, $packet->secondaryPageNumber));
909 $newBook->swapPages($packet->pageNumber, $packet->secondaryPageNumber);
910 $modifiedPages = [$packet->pageNumber, $packet->secondaryPageNumber];
912 case BookEditPacket::TYPE_SIGN_BOOK:
913 $title = self::checkBookText($packet->title,
"title", 16, Limits::INT16_MAX, $cancel);
915 $author = self::checkBookText($packet->author,
"author", 256, Limits::INT16_MAX, $cancel);
917 $newBook = VanillaItems::WRITTEN_BOOK()
918 ->setPages($oldBook->getPages())
921 ->setGeneration(WrittenBook::GENERATION_ORIGINAL);
928 $action = match($packet->type){
929 BookEditPacket::TYPE_REPLACE_PAGE => PlayerEditBookEvent::ACTION_REPLACE_PAGE,
930 BookEditPacket::TYPE_ADD_PAGE => PlayerEditBookEvent::ACTION_ADD_PAGE,
931 BookEditPacket::TYPE_DELETE_PAGE => PlayerEditBookEvent::ACTION_DELETE_PAGE,
932 BookEditPacket::TYPE_SWAP_PAGES => PlayerEditBookEvent::ACTION_SWAP_PAGES,
933 BookEditPacket::TYPE_SIGN_BOOK => PlayerEditBookEvent::ACTION_SIGN_BOOK,
941 $oldPageCount = count($oldBook->getPages());
942 $newPageCount = count($newBook->getPages());
943 if(($newPageCount > $oldPageCount && $newPageCount > 50)){
944 $this->session->getLogger()->debug(
"Cancelled book edit due to adding too many pages (new page count would be $newPageCount)");
948 $event =
new PlayerEditBookEvent($this->player, $oldBook, $newBook, $action, $modifiedPages);
954 if($event->isCancelled()){
958 $this->player->getInventory()->setItem($packet->inventorySlot, $event->getNewBook());
964 if($packet->cancelReason !==
null){
966 return $this->player->onFormSubmit($packet->formId,
null);
967 }elseif($packet->formData !==
null){
968 if(strlen($packet->formData) > self::MAX_FORM_RESPONSE_SIZE){
969 throw new PacketHandlingException(
"Form response data too large, refusing to decode (received" . strlen($packet->formData) .
" bytes, max " . self::MAX_FORM_RESPONSE_SIZE .
" bytes)");
971 if(!$this->player->hasPendingForm($packet->formId)){
972 $this->session->getLogger()->debug(
"Got unexpected response for form $packet->formId");
976 $responseData = json_decode($packet->formData,
true, self::MAX_FORM_RESPONSE_DEPTH, JSON_THROW_ON_ERROR);
977 }
catch(\JsonException $e){
978 throw PacketHandlingException::wrap($e,
"Failed to decode form response data");
980 return $this->player->onFormSubmit($packet->formId, $responseData);
982 throw new PacketHandlingException(
"Expected either formData or cancelReason to be set in ModalFormResponsePacket");
987 $pos = $packet->blockPosition;
988 $chunkX = $pos->getX() >> Chunk::COORD_BIT_SIZE;
989 $chunkZ = $pos->getZ() >> Chunk::COORD_BIT_SIZE;
990 $world = $this->player->getWorld();
991 if(!$world->isChunkLoaded($chunkX, $chunkZ) || $world->isChunkLocked($chunkX, $chunkZ)){
995 $lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ());
996 if($lectern instanceof
Lectern && $this->player->canInteract($lectern->getPosition(), 15)){
997 if(!$lectern->onPageTurn($packet->page)){
998 $this->syncBlocksNearby($lectern->getPosition(),
null);
1006 public function handleEmote(
EmotePacket $packet) :
bool{
1007 $this->player->emote($packet->getEmoteId());