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);
172 private function resolveOnOffInputFlags(
BitSet $inputFlags,
int $startFlag,
int $stopFlag) : ?
bool{
173 $enabled = $inputFlags->get($startFlag);
174 $disabled = $inputFlags->get($stopFlag);
175 if($enabled !== $disabled){
183 $rawPos = $packet->getPosition();
184 $rawYaw = $packet->getYaw();
185 $rawPitch = $packet->getPitch();
186 foreach([$rawPos->x, $rawPos->y, $rawPos->z, $rawYaw, $packet->getHeadYaw(), $rawPitch] as $float){
187 if(is_infinite($float) || is_nan($float)){
188 $this->session->getLogger()->debug(
"Invalid movement received, contains NAN/INF components");
193 if($rawYaw !== $this->lastPlayerAuthInputYaw || $rawPitch !== $this->lastPlayerAuthInputPitch){
194 $this->lastPlayerAuthInputYaw = $rawYaw;
195 $this->lastPlayerAuthInputPitch = $rawPitch;
197 $yaw = fmod($rawYaw, 360);
198 $pitch = fmod($rawPitch, 360);
203 $this->player->setRotation($yaw, $pitch);
206 $hasMoved = $this->lastPlayerAuthInputPosition ===
null || !$this->lastPlayerAuthInputPosition->equals($rawPos);
207 $newPos = $rawPos->subtract(0, 1.62, 0)->round(4);
209 if($this->forceMoveSync && $hasMoved){
210 $curPos = $this->player->getLocation();
212 if($newPos->distanceSquared($curPos) > 1){
213 $this->session->getLogger()->debug(
"Got outdated pre-teleport movement, received " . $newPos .
", expected " . $curPos);
219 $this->forceMoveSync =
false;
222 $inputFlags = $packet->getInputFlags();
223 if($this->lastPlayerAuthInputFlags ===
null || !$inputFlags->equals($this->lastPlayerAuthInputFlags)){
224 $this->lastPlayerAuthInputFlags = $inputFlags;
228 $sneaking = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SNEAKING, PlayerAuthInputFlags::STOP_SNEAKING);
229 $sprinting = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SPRINTING, PlayerAuthInputFlags::STOP_SPRINTING);
230 $swimming = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SWIMMING, PlayerAuthInputFlags::STOP_SWIMMING);
231 $gliding = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_GLIDING, PlayerAuthInputFlags::STOP_GLIDING);
232 $flying = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_FLYING, PlayerAuthInputFlags::STOP_FLYING);
234 (!$this->player->toggleSneak($sneaking ?? $this->player->isSneaking(), $sneakPressed)) |
235 ($sprinting !==
null && !$this->player->toggleSprint($sprinting)) |
236 ($swimming !==
null && !$this->player->toggleSwim($swimming)) |
237 ($gliding !==
null && !$this->player->toggleGlide($gliding)) |
238 ($flying !==
null && !$this->player->toggleFlight($flying));
239 if((
bool) $mismatch){
240 $this->player->sendData([$this->player]);
244 $this->player->jump();
247 $this->player->missSwing();
251 if(!$this->forceMoveSync && $hasMoved){
252 $this->lastPlayerAuthInputPosition = $rawPos;
254 $this->player->handleMovement($newPos);
257 $packetHandled =
true;
259 $useItemTransaction = $packet->getItemInteractionData();
260 if($useItemTransaction !==
null){
261 if(count($useItemTransaction->getTransactionData()->getActions()) > 100){
265 $this->inventoryManager->setCurrentItemStackRequestId($useItemTransaction->getRequestId());
266 $this->inventoryManager->addRawPredictedSlotChanges($useItemTransaction->getTransactionData()->getActions());
267 if(!$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
268 $packetHandled =
false;
269 $this->session->getLogger()->debug(
"Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() .
")");
271 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
273 $this->inventoryManager->setCurrentItemStackRequestId(
null);
276 $itemStackRequest = $packet->getItemStackRequest();
277 $itemStackResponseBuilder = $itemStackRequest !==
null ? $this->handleSingleItemStackRequest($itemStackRequest) :
null;
281 $blockActions = $packet->getBlockActions();
282 if($blockActions !==
null){
283 if(count($blockActions) > 100){
286 foreach(Utils::promoteKeys($blockActions) as $k => $blockAction){
287 $actionHandled =
false;
289 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(),
new BlockPosition(0, 0, 0), Facing::DOWN);
291 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), $blockAction->getBlockPosition(), $blockAction->getFace());
295 $packetHandled =
false;
296 $this->session->getLogger()->debug(
"Unhandled player block action at offset $k in PlayerAuthInputPacket");
301 if($itemStackRequest !==
null){
302 $itemStackResponse = $itemStackResponseBuilder?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $itemStackRequest->getRequestId());
306 return $packetHandled;
316 if(count($packet->trData->getActions()) > 50){
319 if(count($packet->requestChangedSlots) > 10){
323 $this->inventoryManager->setCurrentItemStackRequestId($packet->requestId);
324 $this->inventoryManager->addRawPredictedSlotChanges($packet->trData->getActions());
327 $result = $this->handleNormalTransaction($packet->trData, $packet->requestId);
329 $this->session->getLogger()->debug(
"Mismatch transaction received");
330 $this->inventoryManager->requestSyncAll();
333 $result = $this->handleUseItemTransaction($packet->trData);
335 $result = $this->handleUseItemOnEntityTransaction($packet->trData);
337 $result = $this->handleReleaseItemTransaction($packet->trData);
340 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
346 foreach($packet->requestChangedSlots as $containerInfo){
347 foreach($containerInfo->getChangedSlotIndexes() as $netSlot){
349 $inventoryAndSlot = $this->inventoryManager->locateWindowAndSlot($windowId, $slot);
350 if($inventoryAndSlot !==
null){
351 $this->inventoryManager->onSlotChange($inventoryAndSlot[0], $inventoryAndSlot[1]);
356 $this->inventoryManager->setCurrentItemStackRequestId(
null);
360 private function executeInventoryTransaction(
InventoryTransaction $transaction,
int $requestId) :
bool{
361 $this->player->setUsingItem(
false);
363 $this->inventoryManager->setCurrentItemStackRequestId($requestId);
364 $this->inventoryManager->addTransactionPredictedSlotChanges($transaction);
368 $this->inventoryManager->requestSyncAll();
369 $logger = $this->session->getLogger();
370 $logger->debug(
"Invalid inventory transaction $requestId: " . $e->getMessage());
374 $this->session->getLogger()->debug(
"Inventory transaction $requestId cancelled by a plugin");
378 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
379 $this->inventoryManager->setCurrentItemStackRequestId(
null);
385 private function handleNormalTransaction(
NormalTransactionData $data,
int $itemStackRequestId) :
bool{
392 if($actionCount > 2){
393 if($actionCount > 5){
399 $this->session->getLogger()->debug(
"Ignoring normal inventory transaction with $actionCount actions (drop-item should have exactly 2 actions)");
404 $clientItemStack =
null;
405 $droppedCount =
null;
407 foreach($data->
getActions() as $networkInventoryAction){
408 if($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_WORLD && $networkInventoryAction->inventorySlot === NetworkInventoryAction::ACTION_MAGIC_SLOT_DROP_ITEM){
409 $droppedCount = $networkInventoryAction->newItem->getItemStack()->getCount();
410 if($droppedCount <= 0){
413 }elseif($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER && $networkInventoryAction->windowId === ContainerIds::INVENTORY){
415 $sourceSlot = $networkInventoryAction->inventorySlot;
416 $clientItemStack = $networkInventoryAction->oldItem->getItemStack();
418 $this->session->getLogger()->debug(
"Unexpected inventory action type $networkInventoryAction->sourceType in drop item transaction");
422 if($sourceSlot ===
null || $clientItemStack ===
null || $droppedCount ===
null){
423 $this->session->getLogger()->debug(
"Missing information in drop item transaction, need source slot, client item stack and dropped count");
427 $inventory = $this->player->getInventory();
429 if(!$inventory->slotExists($sourceSlot)){
433 $sourceSlotItem = $inventory->getItem($sourceSlot);
434 if($sourceSlotItem->getCount() < $droppedCount){
437 $serverItemStack = $this->session->getTypeConverter()->coreItemStackToNet($sourceSlotItem);
441 $serverItemStack->getId() !== $clientItemStack->getId() ||
442 $serverItemStack->getMeta() !== $clientItemStack->getMeta() ||
443 $serverItemStack->getCount() !== $clientItemStack->getCount() ||
444 $serverItemStack->getBlockRuntimeId() !== $clientItemStack->getBlockRuntimeId()
454 $droppedItem = $sourceSlotItem->pop($droppedCount);
457 $builder->getInventory($inventory)->setItem($sourceSlot, $sourceSlotItem);
461 return $this->executeInventoryTransaction($transaction, $itemStackRequestId);
465 $this->player->selectHotbarSlot($data->getHotbarSlot());
467 switch($data->getActionType()){
468 case UseItemTransactionData::ACTION_CLICK_BLOCK:
470 $clickPos = $data->getClickPosition();
471 $spamBug = ($this->lastRightClickData !==
null &&
472 microtime(
true) - $this->lastRightClickTime < 0.1 &&
473 $this->lastRightClickData->getPlayerPosition()->distanceSquared($data->getPlayerPosition()) < 0.00001 &&
474 $this->lastRightClickData->getBlockPosition()->equals($data->getBlockPosition()) &&
475 $this->lastRightClickData->getClickPosition()->distanceSquared($clickPos) < 0.00001
478 $this->lastRightClickData = $data;
479 $this->lastRightClickTime = microtime(
true);
485 self::validateFacing($data->getFace());
487 $blockPos = $data->getBlockPosition();
488 $vBlockPos =
new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
489 $this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos);
490 if($data->getClientInteractPrediction() === PredictedResult::SUCCESS){
498 $syncAdjacentFace =
null;
499 if($data->getItemInHand()->getItemStack()->getBlockRuntimeId() === ItemTranslator::NO_BLOCK_RUNTIME_ID){
500 $this->session->getLogger()->debug(
"Placing held item might place multiple blocks client-side; doing full adjacent sync");
501 $syncAdjacentFace = $data->getFace();
503 $this->syncBlocksNearby($vBlockPos, $syncAdjacentFace);
506 case UseItemTransactionData::ACTION_CLICK_AIR:
507 if($this->player->isUsingItem()){
508 if(!$this->player->consumeHeldItem()){
509 $hungerAttr = $this->player->getAttributeMap()->get(Attribute::HUNGER) ??
throw new AssumptionFailedError();
510 $hungerAttr->markSynchronized(
false);
515 $this->player->setUsingItem(
false);
518 $this->player->useHeldItem();
528 private static function validateFacing(
int $facing) :
void{
529 if(!in_array($facing, Facing::ALL,
true)){
537 private function syncBlocksNearby(
Vector3 $blockPos, ?
int $face) :
void{
538 if($blockPos->distanceSquared($this->player->getLocation()) < 10000){
541 $sidePos = $blockPos->
getSide($face);
544 array_push($blocks, ...$sidePos->sidesArray());
546 $blocks[] = $blockPos;
548 foreach($this->player->getWorld()->createBlockUpdatePackets($blocks) as $packet){
549 $this->session->sendDataPacket($packet);
555 $target = $this->player->getWorld()->getEntity($data->getActorRuntimeId());
558 if($target ===
null || $target->isFlaggedForDespawn()){
562 $this->player->selectHotbarSlot($data->getHotbarSlot());
564 switch($data->getActionType()){
565 case UseItemOnEntityTransactionData::ACTION_INTERACT:
566 $this->player->interactEntity($target, $data->getClickPosition());
568 case UseItemOnEntityTransactionData::ACTION_ATTACK:
569 $this->player->attackEntity($target);
577 $this->player->selectHotbarSlot($data->getHotbarSlot());
579 if($data->getActionType() === ReleaseItemTransactionData::ACTION_RELEASE){
580 $this->player->releaseHeldItem();
603 $transaction = $executor->generateInventoryTransaction();
604 if($transaction !==
null){
605 $result = $this->executeInventoryTransaction($transaction, $request->getRequestId());
611 $this->session->getLogger()->debug(
"ItemStackRequest #" . $request->getRequestId() .
" failed: " . $e->getMessage());
612 $this->session->getLogger()->debug(implode(
"\n", Utils::printableExceptionInfo($e)));
613 $this->inventoryManager->requestSyncAll();
616 return $result ? $executor->getItemStackResponseBuilder() :
null;
621 if(count($packet->getRequests()) > 80){
625 foreach($packet->getRequests() as $request){
626 $responses[] = $this->handleSingleItemStackRequest($request)?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $request->getRequestId());
635 if($packet->windowId === ContainerIds::OFFHAND){
638 if($packet->windowId === ContainerIds::INVENTORY){
639 $this->inventoryManager->onClientSelectHotbarSlot($packet->hotbarSlot);
640 if(!$this->player->selectHotbarSlot($packet->hotbarSlot)){
641 $this->inventoryManager->syncSelectedHotbarSlot();
653 if($packet->action === InteractPacket::ACTION_MOUSEOVER){
661 $target = $this->player->getWorld()->getEntity($packet->targetActorRuntimeId);
662 if($target ===
null){
665 if($packet->action === InteractPacket::ACTION_OPEN_INVENTORY && $target === $this->player){
666 $this->inventoryManager->onClientOpenMainInventory();
673 return $this->player->pickBlock(
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ()), $packet->addUserData);
677 return $this->player->pickEntity($packet->actorUniqueId);
681 return $this->handlePlayerActionFromData($packet->action, $packet->blockPosition, $packet->face);
684 private function handlePlayerActionFromData(
int $action,
BlockPosition $blockPosition,
int $face) :
bool{
685 $pos =
new Vector3($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ());
688 case PlayerAction::START_BREAK:
689 case PlayerAction::CONTINUE_DESTROY_BLOCK:
690 self::validateFacing($face);
691 if($this->lastBlockAttacked !==
null && $blockPosition->equals($this->lastBlockAttacked)){
696 $this->session->getLogger()->debug(
"Ignoring PlayerAction $action on $pos because we were already destroying this block");
699 if(!$this->player->attackBlock($pos, $face)){
700 $this->syncBlocksNearby($pos, $face);
702 $this->lastBlockAttacked = $blockPosition;
706 case PlayerAction::ABORT_BREAK:
707 case PlayerAction::STOP_BREAK:
708 $this->player->stopBreakBlock($pos);
709 $this->lastBlockAttacked =
null;
711 case PlayerAction::START_SLEEPING:
714 case PlayerAction::STOP_SLEEPING:
715 $this->player->stopSleep();
717 case PlayerAction::CRACK_BREAK:
718 self::validateFacing($face);
719 $this->player->continueBreakBlock($pos, $face);
720 $this->lastBlockAttacked = $blockPosition;
722 case PlayerAction::INTERACT_BLOCK:
724 case PlayerAction::CREATIVE_PLAYER_DESTROY_BLOCK:
727 case PlayerAction::PREDICT_DESTROY_BLOCK:
728 self::validateFacing($face);
729 if(!$this->player->breakBlock($pos)){
730 $this->syncBlocksNearby($pos, $face);
732 $this->lastBlockAttacked =
null;
734 case PlayerAction::START_ITEM_USE_ON:
735 case PlayerAction::STOP_ITEM_USE_ON:
739 $this->session->getLogger()->debug(
"Unhandled/unknown player action type " . $action);
743 $this->player->setUsingItem(
false);
759 $this->inventoryManager->onClientRemoveWindow($packet->windowId);
771 $textTag = $nbt->
getTag($tagName);
773 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textTag) .
" for tag \"$tagName\" in sign update data");
775 $textBlobTag = $textTag->getTag(Sign::TAG_TEXT_BLOB);
777 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textBlobTag) .
" for tag \"" . Sign::TAG_TEXT_BLOB .
"\" in sign update data");
781 $text = SignText::fromBlob($textBlobTag->getValue());
782 }
catch(\InvalidArgumentException $e){
783 throw PacketHandlingException::wrap($e,
"Invalid sign text update");
786 $oldText = $block->getFaceText($frontFace);
787 if($text->getLines() === $oldText->getLines()){
793 foreach($this->player->getWorld()->createBlockUpdatePackets([$pos]) as $updatePacket){
794 $this->session->sendDataPacket($updatePacket);
799 }
catch(\UnexpectedValueException $e){
800 throw PacketHandlingException::wrap($e);
805 $pos =
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ());
806 if($pos->distanceSquared($this->player->getLocation()) > 10000){
810 $block = $this->player->getLocation()->getWorld()->getBlock($pos);
811 $nbt = $packet->nbt->getRoot();
815 if(!$this->updateSignText($nbt, Sign::TAG_FRONT_TEXT,
true, $block, $pos)){
817 $this->updateSignText($nbt, Sign::TAG_BACK_TEXT,
false, $block, $pos);
827 $gameMode = $this->session->getTypeConverter()->protocolGameModeToCore($packet->gamemode);
828 if($gameMode !== $this->player->getGamemode()){
830 $this->session->syncGameMode($this->player->getGamemode(),
true);
844 $this->player->setViewDistance($packet->radius);
858 if(str_starts_with($packet->command,
'/')){
859 $this->player->chat($packet->command);
870 if($packet->skin->getFullSkinId() === $this->lastRequestedFullSkinId){
873 $this->session->getLogger()->debug(
"Refused duplicate skin change request");
876 $this->lastRequestedFullSkinId = $packet->skin->getFullSkinId();
878 $this->session->getLogger()->debug(
"Processing skin change request");
880 $skin = $this->session->getTypeConverter()->getSkinAdapter()->fromSkinData($packet->skin);
882 throw PacketHandlingException::wrap($e,
"Invalid skin in PlayerSkinPacket");
884 return $this->player->changeSkin($skin, $packet->newSkinName, $packet->oldSkinName);
894 private function checkBookText(
string $string,
string $fieldName,
int $softLimit,
int $hardLimit,
bool &$cancel) :
string{
895 if(strlen($string) > $hardLimit){
896 throw new PacketHandlingException(sprintf(
"Book %s must be at most %d bytes, but have %d bytes", $fieldName, $hardLimit, strlen($string)));
899 $result = TextFormat::clean($string,
false);
901 if(strlen($result) > $softLimit * 4 || mb_strlen($result,
'UTF-8') > $softLimit){
903 $this->session->getLogger()->debug(
"Cancelled book edit due to $fieldName exceeded soft limit of $softLimit chars");
910 $inventory = $this->player->getInventory();
911 if(!$inventory->slotExists($packet->inventorySlot)){
915 $oldBook = $inventory->getItem($packet->inventorySlot);
920 $newBook = clone $oldBook;
923 switch($packet->type){
924 case BookEditPacket::TYPE_REPLACE_PAGE:
925 $text = self::checkBookText($packet->text,
"page text", self::PAGE_LENGTH_SOFT_LIMIT_CHARS, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
926 $newBook->setPageText($packet->pageNumber, $text);
927 $modifiedPages[] = $packet->pageNumber;
929 case BookEditPacket::TYPE_ADD_PAGE:
930 if(!$newBook->pageExists($packet->pageNumber)){
935 $text = self::checkBookText($packet->text,
"page text", self::PAGE_LENGTH_SOFT_LIMIT_CHARS, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
936 $newBook->insertPage($packet->pageNumber, $text);
937 $modifiedPages[] = $packet->pageNumber;
939 case BookEditPacket::TYPE_DELETE_PAGE:
940 if(!$newBook->pageExists($packet->pageNumber)){
943 $newBook->deletePage($packet->pageNumber);
944 $modifiedPages[] = $packet->pageNumber;
946 case BookEditPacket::TYPE_SWAP_PAGES:
947 if(!$newBook->pageExists($packet->pageNumber) || !$newBook->pageExists($packet->secondaryPageNumber)){
949 $newBook->addPage(max($packet->pageNumber, $packet->secondaryPageNumber));
951 $newBook->swapPages($packet->pageNumber, $packet->secondaryPageNumber);
952 $modifiedPages = [$packet->pageNumber, $packet->secondaryPageNumber];
954 case BookEditPacket::TYPE_SIGN_BOOK:
955 $title = self::checkBookText($packet->title,
"title", 16, Limits::INT16_MAX, $cancel);
957 $author = self::checkBookText($packet->author,
"author", 256, Limits::INT16_MAX, $cancel);
959 $newBook = VanillaItems::WRITTEN_BOOK()
960 ->setPages($oldBook->getPages())
963 ->setGeneration(WrittenBook::GENERATION_ORIGINAL);
970 $action = match($packet->type){
971 BookEditPacket::TYPE_REPLACE_PAGE => PlayerEditBookEvent::ACTION_REPLACE_PAGE,
972 BookEditPacket::TYPE_ADD_PAGE => PlayerEditBookEvent::ACTION_ADD_PAGE,
973 BookEditPacket::TYPE_DELETE_PAGE => PlayerEditBookEvent::ACTION_DELETE_PAGE,
974 BookEditPacket::TYPE_SWAP_PAGES => PlayerEditBookEvent::ACTION_SWAP_PAGES,
975 BookEditPacket::TYPE_SIGN_BOOK => PlayerEditBookEvent::ACTION_SIGN_BOOK,
983 $oldPageCount = count($oldBook->getPages());
984 $newPageCount = count($newBook->getPages());
985 if(($newPageCount > $oldPageCount && $newPageCount > 50)){
986 $this->session->getLogger()->debug(
"Cancelled book edit due to adding too many pages (new page count would be $newPageCount)");
990 $event =
new PlayerEditBookEvent($this->player, $oldBook, $newBook, $action, $modifiedPages);
996 if($event->isCancelled()){
1000 $this->player->getInventory()->setItem($packet->inventorySlot, $event->getNewBook());
1006 if($packet->cancelReason !==
null){
1008 return $this->player->onFormSubmit($packet->formId,
null);
1009 }elseif($packet->formData !==
null){
1010 if(strlen($packet->formData) > self::MAX_FORM_RESPONSE_SIZE){
1011 throw new PacketHandlingException(
"Form response data too large, refusing to decode (received" . strlen($packet->formData) .
" bytes, max " . self::MAX_FORM_RESPONSE_SIZE .
" bytes)");
1013 if(!$this->player->hasPendingForm($packet->formId)){
1014 $this->session->getLogger()->debug(
"Got unexpected response for form $packet->formId");
1018 $responseData = json_decode($packet->formData,
true, self::MAX_FORM_RESPONSE_DEPTH, JSON_THROW_ON_ERROR);
1019 }
catch(\JsonException $e){
1020 throw PacketHandlingException::wrap($e,
"Failed to decode form response data");
1022 return $this->player->onFormSubmit($packet->formId, $responseData);
1024 throw new PacketHandlingException(
"Expected either formData or cancelReason to be set in ModalFormResponsePacket");
1037 $pos = $packet->blockPosition;
1038 $chunkX = $pos->getX() >> Chunk::COORD_BIT_SIZE;
1039 $chunkZ = $pos->getZ() >> Chunk::COORD_BIT_SIZE;
1040 $world = $this->player->getWorld();
1041 if(!$world->isChunkLoaded($chunkX, $chunkZ) || $world->isChunkLocked($chunkX, $chunkZ)){
1045 $lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ());
1046 if($lectern instanceof
Lectern && $this->player->canInteract($lectern->getPosition(), 15)){
1047 if(!$lectern->onPageTurn($packet->page)){
1048 $this->syncBlocksNearby($lectern->getPosition(),
null);
1070 public function handleEmote(
EmotePacket $packet) :
bool{
1071 $this->player->emote($packet->getEmoteId());