131 private const MAX_FORM_RESPONSE_SIZE = 10 * 1024;
132 private const MAX_FORM_RESPONSE_DEPTH = 2;
137 private const PAGE_LENGTH_SOFT_LIMIT_CHARS = 512;
139 protected float $lastRightClickTime = 0.0;
142 protected ?
Vector3 $lastPlayerAuthInputPosition =
null;
143 protected ?
float $lastPlayerAuthInputYaw =
null;
144 protected ?
float $lastPlayerAuthInputPitch =
null;
145 protected ?
BitSet $lastPlayerAuthInputFlags =
null;
149 public bool $forceMoveSync =
false;
151 protected ?
string $lastRequestedFullSkinId =
null;
153 public function __construct(
159 public function handleText(
TextPacket $packet) :
bool{
160 if($packet->type === TextPacket::TYPE_CHAT){
161 return $this->player->chat($packet->message);
167 private function resolveOnOffInputFlags(
BitSet $inputFlags,
int $startFlag,
int $stopFlag) : ?
bool{
168 $enabled = $inputFlags->get($startFlag);
169 $disabled = $inputFlags->get($stopFlag);
170 if($enabled !== $disabled){
178 $rawPos = $packet->getPosition();
179 $rawYaw = $packet->getYaw();
180 $rawPitch = $packet->getPitch();
181 foreach([$rawPos->x, $rawPos->y, $rawPos->z, $rawYaw, $packet->getHeadYaw(), $rawPitch] as $float){
182 if(is_infinite($float) || is_nan($float)){
183 $this->session->getLogger()->debug(
"Invalid movement received, contains NAN/INF components");
188 if($rawYaw !== $this->lastPlayerAuthInputYaw || $rawPitch !== $this->lastPlayerAuthInputPitch){
189 $this->lastPlayerAuthInputYaw = $rawYaw;
190 $this->lastPlayerAuthInputPitch = $rawPitch;
192 $yaw = fmod($rawYaw, 360);
193 $pitch = fmod($rawPitch, 360);
198 $this->player->setRotation($yaw, $pitch);
201 $hasMoved = $this->lastPlayerAuthInputPosition ===
null || !$this->lastPlayerAuthInputPosition->equals($rawPos);
202 $newPos = $rawPos->subtract(0, 1.62, 0)->round(4);
204 if($this->forceMoveSync && $hasMoved){
205 $curPos = $this->player->getLocation();
207 if($newPos->distanceSquared($curPos) > 1){
208 $this->session->getLogger()->debug(
"Got outdated pre-teleport movement, received " . $newPos .
", expected " . $curPos);
214 $this->forceMoveSync =
false;
217 $inputFlags = $packet->getInputFlags();
218 if($this->lastPlayerAuthInputFlags ===
null || !$inputFlags->equals($this->lastPlayerAuthInputFlags)){
219 $this->lastPlayerAuthInputFlags = $inputFlags;
223 $sneaking = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SNEAKING, PlayerAuthInputFlags::STOP_SNEAKING);
224 $sprinting = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SPRINTING, PlayerAuthInputFlags::STOP_SPRINTING);
225 $swimming = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SWIMMING, PlayerAuthInputFlags::STOP_SWIMMING);
226 $gliding = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_GLIDING, PlayerAuthInputFlags::STOP_GLIDING);
227 $flying = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_FLYING, PlayerAuthInputFlags::STOP_FLYING);
229 (!$this->player->toggleSneak($sneaking ?? $this->player->isSneaking(), $sneakPressed)) |
230 ($sprinting !==
null && !$this->player->toggleSprint($sprinting)) |
231 ($swimming !==
null && !$this->player->toggleSwim($swimming)) |
232 ($gliding !==
null && !$this->player->toggleGlide($gliding)) |
233 ($flying !==
null && !$this->player->toggleFlight($flying));
234 if((
bool) $mismatch){
235 $this->player->sendData([$this->player]);
239 $this->player->jump();
242 $this->player->missSwing();
246 if(!$this->forceMoveSync && $hasMoved){
247 $this->lastPlayerAuthInputPosition = $rawPos;
249 $this->player->handleMovement($newPos);
252 $packetHandled =
true;
254 $useItemTransaction = $packet->getItemInteractionData();
255 if($useItemTransaction !==
null){
256 if(count($useItemTransaction->getTransactionData()->getActions()) > 100){
260 $this->inventoryManager->setCurrentItemStackRequestId($useItemTransaction->getRequestId());
261 $this->inventoryManager->addRawPredictedSlotChanges($useItemTransaction->getTransactionData()->getActions());
262 if(!$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
263 $packetHandled =
false;
264 $this->session->getLogger()->debug(
"Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() .
")");
266 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
268 $this->inventoryManager->setCurrentItemStackRequestId(
null);
271 $itemStackRequest = $packet->getItemStackRequest();
272 $itemStackResponseBuilder = $itemStackRequest !==
null ? $this->handleSingleItemStackRequest($itemStackRequest) :
null;
276 $blockActions = $packet->getBlockActions();
277 if($blockActions !==
null){
278 if(count($blockActions) > 100){
281 foreach(Utils::promoteKeys($blockActions) as $k => $blockAction){
282 $actionHandled =
false;
284 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(),
new BlockPosition(0, 0, 0), Facing::DOWN);
286 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), $blockAction->getBlockPosition(), $blockAction->getFace());
290 $packetHandled =
false;
291 $this->session->getLogger()->debug(
"Unhandled player block action at offset $k in PlayerAuthInputPacket");
296 if($itemStackRequest !==
null){
297 $itemStackResponse = $itemStackResponseBuilder?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $itemStackRequest->getRequestId());
301 return $packetHandled;
307 if(count($packet->trData->getActions()) > 50){
310 if(count($packet->requestChangedSlots) > 10){
314 $this->inventoryManager->setCurrentItemStackRequestId($packet->requestId);
315 $this->inventoryManager->addRawPredictedSlotChanges($packet->trData->getActions());
318 $result = $this->handleNormalTransaction($packet->trData, $packet->requestId);
320 $this->session->getLogger()->debug(
"Mismatch transaction received");
321 $this->inventoryManager->requestSyncAll();
324 $result = $this->handleUseItemTransaction($packet->trData);
326 $result = $this->handleUseItemOnEntityTransaction($packet->trData);
328 $result = $this->handleReleaseItemTransaction($packet->trData);
331 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
337 foreach($packet->requestChangedSlots as $containerInfo){
338 foreach($containerInfo->getChangedSlotIndexes() as $netSlot){
340 $inventoryAndSlot = $this->inventoryManager->locateWindowAndSlot($windowId, $slot);
341 if($inventoryAndSlot !==
null){
342 $this->inventoryManager->onSlotChange($inventoryAndSlot[0], $inventoryAndSlot[1]);
347 $this->inventoryManager->setCurrentItemStackRequestId(
null);
351 private function executeInventoryTransaction(
InventoryTransaction $transaction,
int $requestId) :
bool{
352 $this->player->setUsingItem(
false);
354 $this->inventoryManager->setCurrentItemStackRequestId($requestId);
355 $this->inventoryManager->addTransactionPredictedSlotChanges($transaction);
359 $this->inventoryManager->requestSyncAll();
360 $logger = $this->session->getLogger();
361 $logger->debug(
"Invalid inventory transaction $requestId: " . $e->getMessage());
365 $this->session->getLogger()->debug(
"Inventory transaction $requestId cancelled by a plugin");
369 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
370 $this->inventoryManager->setCurrentItemStackRequestId(
null);
376 private function handleNormalTransaction(
NormalTransactionData $data,
int $itemStackRequestId) :
bool{
383 if($actionCount > 2){
384 if($actionCount > 5){
390 $this->session->getLogger()->debug(
"Ignoring normal inventory transaction with $actionCount actions (drop-item should have exactly 2 actions)");
395 $clientItemStack =
null;
396 $droppedCount =
null;
398 foreach($data->
getActions() as $networkInventoryAction){
399 if($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_WORLD && $networkInventoryAction->inventorySlot === NetworkInventoryAction::ACTION_MAGIC_SLOT_DROP_ITEM){
400 $droppedCount = $networkInventoryAction->newItem->getItemStack()->getCount();
401 if($droppedCount <= 0){
404 }elseif($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER && $networkInventoryAction->windowId === ContainerIds::INVENTORY){
406 $sourceSlot = $networkInventoryAction->inventorySlot;
407 $clientItemStack = $networkInventoryAction->oldItem->getItemStack();
409 $this->session->getLogger()->debug(
"Unexpected inventory action type $networkInventoryAction->sourceType in drop item transaction");
413 if($sourceSlot ===
null || $clientItemStack ===
null || $droppedCount ===
null){
414 $this->session->getLogger()->debug(
"Missing information in drop item transaction, need source slot, client item stack and dropped count");
418 $inventory = $this->player->getInventory();
420 if(!$inventory->slotExists($sourceSlot)){
424 $sourceSlotItem = $inventory->getItem($sourceSlot);
425 if($sourceSlotItem->getCount() < $droppedCount){
428 $serverItemStack = $this->session->getTypeConverter()->coreItemStackToNet($sourceSlotItem);
432 $serverItemStack->getId() !== $clientItemStack->getId() ||
433 $serverItemStack->getMeta() !== $clientItemStack->getMeta() ||
434 $serverItemStack->getCount() !== $clientItemStack->getCount() ||
435 $serverItemStack->getBlockRuntimeId() !== $clientItemStack->getBlockRuntimeId()
445 $droppedItem = $sourceSlotItem->pop($droppedCount);
448 $builder->getInventory($inventory)->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->getFace() === $data->getFace() &&
465 $this->lastRightClickData->getPlayerPosition()->distanceSquared($data->getPlayerPosition()) < 0.00001 &&
466 $this->lastRightClickData->getBlockPosition()->equals($data->getBlockPosition()) &&
467 $this->lastRightClickData->getClickPosition()->distanceSquared($clickPos) < 0.00001
470 $this->lastRightClickData = $data;
471 $this->lastRightClickTime = microtime(
true);
477 self::validateFacing($data->getFace());
479 $blockPos = $data->getBlockPosition();
480 $vBlockPos =
new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
481 $this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos);
482 if($data->getClientInteractPrediction() === PredictedResult::SUCCESS){
490 $syncAdjacentFace =
null;
491 if($data->getItemInHand()->getItemStack()->getBlockRuntimeId() === ItemTranslator::NO_BLOCK_RUNTIME_ID){
492 $this->session->getLogger()->debug(
"Placing held item might place multiple blocks client-side; doing full adjacent sync");
493 $syncAdjacentFace = $data->getFace();
495 $this->syncBlocksNearby($vBlockPos, $syncAdjacentFace);
498 case UseItemTransactionData::ACTION_CLICK_AIR:
499 if($this->player->isUsingItem()){
500 if(!$this->player->consumeHeldItem()){
501 $hungerAttr = $this->player->getAttributeMap()->get(Attribute::HUNGER) ??
throw new AssumptionFailedError();
502 $hungerAttr->markSynchronized(
false);
507 $this->player->setUsingItem(
false);
510 $this->player->useHeldItem();
520 private static function validateFacing(
int $facing) :
void{
521 if(!in_array($facing, Facing::ALL,
true)){
529 private function syncBlocksNearby(
Vector3 $blockPos, ?
int $face) :
void{
530 if($blockPos->distanceSquared($this->player->getLocation()) < 10000){
533 $sidePos = $blockPos->
getSide($face);
536 array_push($blocks, ...$sidePos->sidesArray());
538 $blocks[] = $blockPos;
540 foreach($this->player->getWorld()->createBlockUpdatePackets($blocks) as $packet){
541 $this->session->sendDataPacket($packet);
547 $target = $this->player->getWorld()->getEntity($data->getActorRuntimeId());
550 if($target ===
null || $target->isFlaggedForDespawn()){
554 $this->player->selectHotbarSlot($data->getHotbarSlot());
556 switch($data->getActionType()){
557 case UseItemOnEntityTransactionData::ACTION_INTERACT:
558 $this->player->interactEntity($target, $data->getClickPosition());
560 case UseItemOnEntityTransactionData::ACTION_ATTACK:
561 $this->player->attackEntity($target);
569 $this->player->selectHotbarSlot($data->getHotbarSlot());
571 if($data->getActionType() === ReleaseItemTransactionData::ACTION_RELEASE){
572 $this->player->releaseHeldItem();
595 $transaction = $executor->generateInventoryTransaction();
596 if($transaction !==
null){
597 $result = $this->executeInventoryTransaction($transaction, $request->getRequestId());
603 $this->session->getLogger()->debug(
"ItemStackRequest #" . $request->getRequestId() .
" failed: " . $e->getMessage());
604 $this->session->getLogger()->debug(implode(
"\n", Utils::printableExceptionInfo($e)));
605 $this->inventoryManager->requestSyncAll();
608 return $result ? $executor->getItemStackResponseBuilder() :
null;
613 if(count($packet->getRequests()) > 80){
617 foreach($packet->getRequests() as $request){
618 $responses[] = $this->handleSingleItemStackRequest($request)?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $request->getRequestId());
627 if($packet->windowId === ContainerIds::OFFHAND){
630 if($packet->windowId === ContainerIds::INVENTORY){
631 $this->inventoryManager->onClientSelectHotbarSlot($packet->hotbarSlot);
632 if(!$this->player->selectHotbarSlot($packet->hotbarSlot)){
633 $this->inventoryManager->syncSelectedHotbarSlot();
641 if($packet->action === InteractPacket::ACTION_MOUSEOVER){
649 $target = $this->player->getWorld()->getEntity($packet->targetActorRuntimeId);
650 if($target ===
null){
653 if($packet->action === InteractPacket::ACTION_OPEN_INVENTORY && $target === $this->player){
654 $this->inventoryManager->onClientOpenMainInventory();
661 return $this->player->pickBlock(
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ()), $packet->addUserData);
665 return $this->player->pickEntity($packet->actorUniqueId);
669 return $this->handlePlayerActionFromData($packet->action, $packet->blockPosition, $packet->face);
672 private function handlePlayerActionFromData(
int $action,
BlockPosition $blockPosition,
int $face) :
bool{
673 $pos =
new Vector3($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ());
676 case PlayerAction::START_BREAK:
677 case PlayerAction::CONTINUE_DESTROY_BLOCK:
678 self::validateFacing($face);
679 if($this->lastBlockAttacked !==
null && $blockPosition->equals($this->lastBlockAttacked)){
684 $this->session->getLogger()->debug(
"Ignoring PlayerAction $action on $pos because we were already destroying this block");
687 if(!$this->player->attackBlock($pos, $face)){
688 $this->syncBlocksNearby($pos, $face);
690 $this->lastBlockAttacked = $blockPosition;
694 case PlayerAction::ABORT_BREAK:
695 case PlayerAction::STOP_BREAK:
696 $this->player->stopBreakBlock($pos);
697 $this->lastBlockAttacked =
null;
699 case PlayerAction::START_SLEEPING:
702 case PlayerAction::STOP_SLEEPING:
703 $this->player->stopSleep();
705 case PlayerAction::CRACK_BREAK:
706 self::validateFacing($face);
707 $this->player->continueBreakBlock($pos, $face);
708 $this->lastBlockAttacked = $blockPosition;
710 case PlayerAction::INTERACT_BLOCK:
712 case PlayerAction::CREATIVE_PLAYER_DESTROY_BLOCK:
715 case PlayerAction::PREDICT_DESTROY_BLOCK:
716 self::validateFacing($face);
717 if(!$this->player->breakBlock($pos)){
718 $this->syncBlocksNearby($pos, $face);
720 $this->lastBlockAttacked =
null;
722 case PlayerAction::START_ITEM_USE_ON:
723 case PlayerAction::STOP_ITEM_USE_ON:
727 $this->session->getLogger()->debug(
"Unhandled/unknown player action type " . $action);
731 $this->player->setUsingItem(
false);
743 $this->inventoryManager->onClientRemoveWindow($packet->windowId);
751 $textTag = $nbt->
getTag($tagName);
753 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textTag) .
" for tag \"$tagName\" in sign update data");
755 $textBlobTag = $textTag->getTag(Sign::TAG_TEXT_BLOB);
757 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textBlobTag) .
" for tag \"" . Sign::TAG_TEXT_BLOB .
"\" in sign update data");
761 $text = SignText::fromBlob($textBlobTag->getValue());
762 }
catch(\InvalidArgumentException $e){
763 throw PacketHandlingException::wrap($e,
"Invalid sign text update");
766 $oldText = $block->getFaceText($frontFace);
767 if($text->getLines() === $oldText->getLines()){
773 foreach($this->player->getWorld()->createBlockUpdatePackets([$pos]) as $updatePacket){
774 $this->session->sendDataPacket($updatePacket);
779 }
catch(\UnexpectedValueException $e){
780 throw PacketHandlingException::wrap($e);
785 $pos =
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ());
786 if($pos->distanceSquared($this->player->getLocation()) > 10000){
790 $block = $this->player->getLocation()->getWorld()->getBlock($pos);
791 $nbt = $packet->nbt->getRoot();
795 if(!$this->updateSignText($nbt, Sign::TAG_FRONT_TEXT,
true, $block, $pos)){
797 $this->updateSignText($nbt, Sign::TAG_BACK_TEXT,
false, $block, $pos);
807 $gameMode = $this->session->getTypeConverter()->protocolGameModeToCore($packet->gamemode);
808 if($gameMode !== $this->player->getGamemode()){
810 $this->session->syncGameMode($this->player->getGamemode(),
true);
816 $this->player->setViewDistance($packet->radius);
822 if(str_starts_with($packet->command,
'/')){
823 $this->player->chat($packet->command);
830 if($packet->skin->getFullSkinId() === $this->lastRequestedFullSkinId){
833 $this->session->getLogger()->debug(
"Refused duplicate skin change request");
836 $this->lastRequestedFullSkinId = $packet->skin->getFullSkinId();
838 $this->session->getLogger()->debug(
"Processing skin change request");
840 $skin = $this->session->getTypeConverter()->getSkinAdapter()->fromSkinData($packet->skin);
842 throw PacketHandlingException::wrap($e,
"Invalid skin in PlayerSkinPacket");
844 return $this->player->changeSkin($skin, $packet->newSkinName, $packet->oldSkinName);
850 private function checkBookText(
string $string,
string $fieldName,
int $softLimit,
int $hardLimit,
bool &$cancel) :
string{
851 if(strlen($string) > $hardLimit){
852 throw new PacketHandlingException(sprintf(
"Book %s must be at most %d bytes, but have %d bytes", $fieldName, $hardLimit, strlen($string)));
855 $result = TextFormat::clean($string,
false);
857 if(strlen($result) > $softLimit * 4 || mb_strlen($result,
'UTF-8') > $softLimit){
859 $this->session->getLogger()->debug(
"Cancelled book edit due to $fieldName exceeded soft limit of $softLimit chars");
866 $inventory = $this->player->getInventory();
867 if(!$inventory->slotExists($packet->inventorySlot)){
871 $oldBook = $inventory->getItem($packet->inventorySlot);
876 $newBook = clone $oldBook;
879 switch($packet->type){
880 case BookEditPacket::TYPE_REPLACE_PAGE:
881 $text = self::checkBookText($packet->text,
"page text", self::PAGE_LENGTH_SOFT_LIMIT_CHARS, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
882 $newBook->setPageText($packet->pageNumber, $text);
883 $modifiedPages[] = $packet->pageNumber;
885 case BookEditPacket::TYPE_ADD_PAGE:
886 if(!$newBook->pageExists($packet->pageNumber)){
891 $text = self::checkBookText($packet->text,
"page text", self::PAGE_LENGTH_SOFT_LIMIT_CHARS, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
892 $newBook->insertPage($packet->pageNumber, $text);
893 $modifiedPages[] = $packet->pageNumber;
895 case BookEditPacket::TYPE_DELETE_PAGE:
896 if(!$newBook->pageExists($packet->pageNumber)){
899 $newBook->deletePage($packet->pageNumber);
900 $modifiedPages[] = $packet->pageNumber;
902 case BookEditPacket::TYPE_SWAP_PAGES:
903 if(!$newBook->pageExists($packet->pageNumber) || !$newBook->pageExists($packet->secondaryPageNumber)){
905 $newBook->addPage(max($packet->pageNumber, $packet->secondaryPageNumber));
907 $newBook->swapPages($packet->pageNumber, $packet->secondaryPageNumber);
908 $modifiedPages = [$packet->pageNumber, $packet->secondaryPageNumber];
910 case BookEditPacket::TYPE_SIGN_BOOK:
911 $title = self::checkBookText($packet->title,
"title", 16, Limits::INT16_MAX, $cancel);
913 $author = self::checkBookText($packet->author,
"author", 256, Limits::INT16_MAX, $cancel);
915 $newBook = VanillaItems::WRITTEN_BOOK()
916 ->setPages($oldBook->getPages())
919 ->setGeneration(WrittenBook::GENERATION_ORIGINAL);
926 $action = match($packet->type){
927 BookEditPacket::TYPE_REPLACE_PAGE => PlayerEditBookEvent::ACTION_REPLACE_PAGE,
928 BookEditPacket::TYPE_ADD_PAGE => PlayerEditBookEvent::ACTION_ADD_PAGE,
929 BookEditPacket::TYPE_DELETE_PAGE => PlayerEditBookEvent::ACTION_DELETE_PAGE,
930 BookEditPacket::TYPE_SWAP_PAGES => PlayerEditBookEvent::ACTION_SWAP_PAGES,
931 BookEditPacket::TYPE_SIGN_BOOK => PlayerEditBookEvent::ACTION_SIGN_BOOK,
939 $oldPageCount = count($oldBook->getPages());
940 $newPageCount = count($newBook->getPages());
941 if(($newPageCount > $oldPageCount && $newPageCount > 50)){
942 $this->session->getLogger()->debug(
"Cancelled book edit due to adding too many pages (new page count would be $newPageCount)");
946 $event =
new PlayerEditBookEvent($this->player, $oldBook, $newBook, $action, $modifiedPages);
952 if($event->isCancelled()){
956 $this->player->getInventory()->setItem($packet->inventorySlot, $event->getNewBook());
962 if($packet->cancelReason !==
null){
964 return $this->player->onFormSubmit($packet->formId,
null);
965 }elseif($packet->formData !==
null){
966 if(strlen($packet->formData) > self::MAX_FORM_RESPONSE_SIZE){
967 throw new PacketHandlingException(
"Form response data too large, refusing to decode (received" . strlen($packet->formData) .
" bytes, max " . self::MAX_FORM_RESPONSE_SIZE .
" bytes)");
969 if(!$this->player->hasPendingForm($packet->formId)){
970 $this->session->getLogger()->debug(
"Got unexpected response for form $packet->formId");
974 $responseData = json_decode($packet->formData,
true, self::MAX_FORM_RESPONSE_DEPTH, JSON_THROW_ON_ERROR);
975 }
catch(\JsonException $e){
976 throw PacketHandlingException::wrap($e,
"Failed to decode form response data");
978 return $this->player->onFormSubmit($packet->formId, $responseData);
980 throw new PacketHandlingException(
"Expected either formData or cancelReason to be set in ModalFormResponsePacket");
985 $pos = $packet->blockPosition;
986 $chunkX = $pos->getX() >> Chunk::COORD_BIT_SIZE;
987 $chunkZ = $pos->getZ() >> Chunk::COORD_BIT_SIZE;
988 $world = $this->player->getWorld();
989 if(!$world->isChunkLoaded($chunkX, $chunkZ) || $world->isChunkLocked($chunkX, $chunkZ)){
993 $lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ());
994 if($lectern instanceof
Lectern && $this->player->canInteract($lectern->getPosition(), 15)){
995 if(!$lectern->onPageTurn($packet->page)){
996 $this->syncBlocksNearby($lectern->getPosition(),
null);
1004 public function handleEmote(
EmotePacket $packet) :
bool{
1005 $this->player->emote($packet->getEmoteId());