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.
This commit is contained in:
Dylan K. Taylor
2022-01-03 20:20:32 +00:00
parent decd1da2d0
commit e43e0189df

View File

@@ -762,7 +762,16 @@ class InGamePacketHandler extends PacketHandler{
return false; 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(); $event->call();
if($event->isCancelled()){ if($event->isCancelled()){
return true; return true;