From e43e0189df0a4a2051edb6bf0514d9a9d353b1a1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Jan 2022 20:20:32 +0000 Subject: [PATCH] InGamePacketHandler: do not pass bare integers from BookEditPacket directly into event while these currently happen to be identical, they may not be in the future. Really this should be represented by an enum. --- src/network/mcpe/handler/InGamePacketHandler.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index b2fd157ad..04e1c847b 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -762,7 +762,16 @@ class InGamePacketHandler extends PacketHandler{ return false; } - $event = new PlayerEditBookEvent($this->player, $oldBook, $newBook, $packet->type, $modifiedPages); + //for redundancy, in case of protocol changes, we don't want to pass these directly + $action = match($packet->type){ + BookEditPacket::TYPE_REPLACE_PAGE => PlayerEditBookEvent::ACTION_REPLACE_PAGE, + BookEditPacket::TYPE_ADD_PAGE => PlayerEditBookEvent::ACTION_ADD_PAGE, + BookEditPacket::TYPE_DELETE_PAGE => PlayerEditBookEvent::ACTION_DELETE_PAGE, + BookEditPacket::TYPE_SWAP_PAGES => PlayerEditBookEvent::ACTION_SWAP_PAGES, + BookEditPacket::TYPE_SIGN_BOOK => PlayerEditBookEvent::ACTION_SIGN_BOOK, + default => throw new AssumptionFailedError("We already filtered unknown types in the switch above") + }; + $event = new PlayerEditBookEvent($this->player, $oldBook, $newBook, $action, $modifiedPages); $event->call(); if($event->isCancelled()){ return true;