From 199ef7401f0bf266362dd48ddd0611e3ca1b79ef Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2023 21:49:25 +0100 Subject: [PATCH 01/10] Revert "Timings: do not shorten event handler timing names" This reverts commit a2ff9649d5f9a14a2bb6e9ab7bab4ea731d225a3. --- src/timings/Timings.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/timings/Timings.php b/src/timings/Timings.php index 74567ce4c..c56929078 100644 --- a/src/timings/Timings.php +++ b/src/timings/Timings.php @@ -310,7 +310,12 @@ abstract class Timings{ public static function getEventTimings(Event $event) : TimingsHandler{ $eventClass = get_class($event); if(!isset(self::$events[$eventClass])){ - self::$events[$eventClass] = new TimingsHandler($eventClass, group: "Events"); + if(str_starts_with($eventClass, "pocketmine\\event\\")){ + $name = (new \ReflectionClass($event))->getShortName(); + }else{ + $name = $eventClass; + } + self::$events[$eventClass] = new TimingsHandler($name, group: "Events"); } return self::$events[$eventClass]; From a6a360d1792317f57a44789d05cacd8186e3e79e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2023 21:51:00 +0100 Subject: [PATCH 02/10] Revert "Be more concise in event handler timing names" This reverts commit 9db7e5f0ca984f17d6a8218d1c74b9be1c605863. --- src/plugin/PluginManager.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/plugin/PluginManager.php b/src/plugin/PluginManager.php index c7a4063fc..d109b23fa 100644 --- a/src/plugin/PluginManager.php +++ b/src/plugin/PluginManager.php @@ -63,10 +63,7 @@ use function realpath; use function shuffle; use function sprintf; use function str_contains; -use function str_starts_with; -use function strlen; use function strtolower; -use function substr; /** * Manages all the plugins @@ -654,11 +651,6 @@ class PluginManager{ throw new PluginException("Plugin attempted to register event handler " . $handlerName . "() to event " . $event . " while not enabled"); } - $prefix = $plugin->getDescription()->getSrcNamespacePrefix(); - if(str_starts_with($handlerName, $prefix) && $prefix !== ""){ - $handlerName = substr($handlerName, strlen($prefix) + 1); - } - $timings = new TimingsHandler($handlerName . "(" . (new \ReflectionClass($event))->getShortName() . ")", group: $plugin->getDescription()->getFullName()); $registeredListener = new RegisteredListener($handler, $priority, $plugin, $handleCancelled, $timings); From 73522d06ef55623bbdeb6d1b6119af1e89e22483 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2023 21:51:07 +0100 Subject: [PATCH 03/10] ... --- src/timings/Timings.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/timings/Timings.php b/src/timings/Timings.php index c56929078..864abf391 100644 --- a/src/timings/Timings.php +++ b/src/timings/Timings.php @@ -31,6 +31,7 @@ use pocketmine\network\mcpe\protocol\ServerboundPacket; use pocketmine\player\Player; use pocketmine\scheduler\TaskHandler; use function get_class; +use function str_starts_with; abstract class Timings{ public const INCLUDED_BY_OTHER_TIMINGS_PREFIX = "** "; From 6e8eda4ac1f08a15e0248e72a6751f0abd863d65 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Apr 2023 22:22:21 +0100 Subject: [PATCH 04/10] Fixed creative inventory items getting modified by ItemStackRequests --- src/inventory/CreativeInventory.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/inventory/CreativeInventory.php b/src/inventory/CreativeInventory.php index 25d3152a4..7d6754f8c 100644 --- a/src/inventory/CreativeInventory.php +++ b/src/inventory/CreativeInventory.php @@ -27,6 +27,7 @@ use pocketmine\item\Durable; use pocketmine\item\Item; use pocketmine\utils\Filesystem; use pocketmine\utils\SingletonTrait; +use pocketmine\utils\Utils; use Symfony\Component\Filesystem\Path; use function json_decode; @@ -60,11 +61,11 @@ final class CreativeInventory{ * @return Item[] */ public function getAll() : array{ - return $this->creative; + return Utils::cloneObjectArray($this->creative); } public function getItem(int $index) : ?Item{ - return $this->creative[$index] ?? null; + return isset($this->creative[$index]) ? clone $this->creative[$index] : null; } public function getItemIndex(Item $item) : int{ From 4bb8daa1a5006e5fc07ecb78e8f07e44fa72705b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Apr 2023 22:24:40 +0100 Subject: [PATCH 05/10] ItemStackRequestExecutor: allow any action to take from the created output slot fixes #5679 --- .../mcpe/handler/ItemStackRequestExecutor.php | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/network/mcpe/handler/ItemStackRequestExecutor.php b/src/network/mcpe/handler/ItemStackRequestExecutor.php index 840a23cc1..81d820c2b 100644 --- a/src/network/mcpe/handler/ItemStackRequestExecutor.php +++ b/src/network/mcpe/handler/ItemStackRequestExecutor.php @@ -147,6 +147,11 @@ class ItemStackRequestExecutor{ * @throws ItemStackRequestProcessException */ protected function removeItemFromSlot(ItemStackRequestSlotInfo $slotInfo, int $count) : Item{ + if($slotInfo->getContainerId() === ContainerUIIds::CREATED_OUTPUT && $slotInfo->getSlotId() === UIInventorySlotOffset::CREATED_ITEM_OUTPUT){ + //special case for the "created item" output slot + //TODO: do we need to send a response for this slot info? + return $this->takeCreatedItem($count); + } $this->requestSlotInfos[] = $slotInfo; [$inventory, $slot] = $this->getBuilderInventoryAndSlot($slotInfo); if($count < 1){ @@ -188,6 +193,13 @@ class ItemStackRequestExecutor{ $inventory->setItem($slot, $newItem); } + protected function dropItem(Item $item, int $count) : void{ + if($count < 1){ + throw new ItemStackRequestProcessException("Cannot drop less than 1 of an item"); + } + $this->builder->addAction(new DropItemAction((clone $item)->setCount($count))); + } + /** * @throws ItemStackRequestProcessException */ @@ -254,7 +266,7 @@ class ItemStackRequestExecutor{ /** * @throws ItemStackRequestProcessException */ - protected function takeCreatedItem(ItemStackRequestSlotInfo $destination, int $count) : void{ + protected function takeCreatedItem(int $count) : Item{ if($count < 1){ //this should be impossible at the protocol level, but in case of buggy core code this will prevent exploits throw new ItemStackRequestProcessException("Cannot take less than 1 created item"); @@ -272,10 +284,12 @@ class ItemStackRequestExecutor{ } $this->createdItemsTakenCount += $count; - $this->addItemToSlot($destination, $createdItem, $count); + $createdItem = clone $createdItem; + $createdItem->setCount($count); if(!$this->createdItemFromCreativeInventory && $this->createdItemsTakenCount >= $createdItem->getCount()){ $this->setNextCreatedItem(null); } + return $createdItem; } /** @@ -299,14 +313,7 @@ class ItemStackRequestExecutor{ $action instanceof TakeStackRequestAction || $action instanceof PlaceStackRequestAction ){ - $source = $action->getSource(); - $destination = $action->getDestination(); - - if($source->getContainerId() === ContainerUIIds::CREATED_OUTPUT && $source->getSlotId() === UIInventorySlotOffset::CREATED_ITEM_OUTPUT){ - $this->takeCreatedItem($destination, $action->getCount()); - }else{ - $this->transferItems($source, $destination, $action->getCount()); - } + $this->transferItems($action->getSource(), $action->getDestination(), $action->getCount()); }elseif($action instanceof SwapStackRequestAction){ $this->requestSlotInfos[] = $action->getSlot1(); $this->requestSlotInfos[] = $action->getSlot2(); From 9cd07f6721fd38e5aa8ddf9cea548f39543a095d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Apr 2023 22:37:13 +0100 Subject: [PATCH 06/10] NetworkBroadcastUtils: remove dead code we don't allow changing the target list anymore, since it increases internal complexity, so this code is redundant. --- src/network/mcpe/NetworkBroadcastUtils.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/network/mcpe/NetworkBroadcastUtils.php b/src/network/mcpe/NetworkBroadcastUtils.php index 8d04d35c5..ce173119e 100644 --- a/src/network/mcpe/NetworkBroadcastUtils.php +++ b/src/network/mcpe/NetworkBroadcastUtils.php @@ -62,7 +62,6 @@ final class NetworkBroadcastUtils{ if($ev->isCancelled()){ return false; } - $sessions = $ev->getTargets(); /** @var PacketBroadcaster[] $uniqueBroadcasters */ $uniqueBroadcasters = []; From 2936726bf8a8e18cd07eaf5c0f563a50589f7916 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Apr 2023 22:46:14 +0100 Subject: [PATCH 07/10] Fixed packets sent by EntityEventBroadcaster not firing DataPacketSendEvent closes #5670 I'm not super happy with this fix, since it can still be broken if StandardPacketBroadcaster is replaced by something else. However, fixing that problem is probably going to require internal BC breaks, which are not suitable for a patch release. --- src/network/mcpe/NetworkBroadcastUtils.php | 7 ------- src/network/mcpe/StandardPacketBroadcaster.php | 10 ++++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/network/mcpe/NetworkBroadcastUtils.php b/src/network/mcpe/NetworkBroadcastUtils.php index ce173119e..76ae98738 100644 --- a/src/network/mcpe/NetworkBroadcastUtils.php +++ b/src/network/mcpe/NetworkBroadcastUtils.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace pocketmine\network\mcpe; -use pocketmine\event\server\DataPacketSendEvent; use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\player\Player; use pocketmine\timings\Timings; @@ -57,12 +56,6 @@ final class NetworkBroadcastUtils{ return false; } - $ev = new DataPacketSendEvent($sessions, $packets); - $ev->call(); - if($ev->isCancelled()){ - return false; - } - /** @var PacketBroadcaster[] $uniqueBroadcasters */ $uniqueBroadcasters = []; /** @var NetworkSession[][] $broadcasterTargets */ diff --git a/src/network/mcpe/StandardPacketBroadcaster.php b/src/network/mcpe/StandardPacketBroadcaster.php index 1ed0f16ae..da9fa5101 100644 --- a/src/network/mcpe/StandardPacketBroadcaster.php +++ b/src/network/mcpe/StandardPacketBroadcaster.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe; +use pocketmine\event\server\DataPacketSendEvent; use pocketmine\network\mcpe\protocol\serializer\PacketBatch; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext; @@ -41,6 +42,15 @@ final class StandardPacketBroadcaster implements PacketBroadcaster{ ){} public function broadcastPackets(array $recipients, array $packets) : void{ + //TODO: this shouldn't really be called here, since the broadcaster might be replaced by an alternative + //implementation that doesn't fire events + $ev = new DataPacketSendEvent($recipients, $packets); + $ev->call(); + if($ev->isCancelled()){ + return; + } + $packets = $ev->getPackets(); + $compressors = []; /** @var NetworkSession[][] $targetsByCompressor */ From 8b64ea9e658f92fddd8dbb0dd8e3826bf05e7d9c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 5 Apr 2023 20:07:23 +0100 Subject: [PATCH 08/10] Release 4.18.3 --- changelogs/4.18.md | 12 ++++++++++++ src/VersionInfo.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/changelogs/4.18.md b/changelogs/4.18.md index 435784fb0..890f00d6d 100644 --- a/changelogs/4.18.md +++ b/changelogs/4.18.md @@ -97,3 +97,15 @@ Released 29th March 2023. ## Fixes - Fixed players being unable to join due to the appearance of a new `x5t` field in the JWT header of Xbox Live authentication tokens. - Fixed items' durability appearing to reset when moving them around in the inventory. + +# 4.18.3 +Released 5th April 2023. + +## Fixes +- Fixed Average Players not being shown on timings reports when custom player classes are used. +- Fixed incorrect tick violation calculation in timings reports. +- Fixed not being able to add or remove items from the offhand slot. +- Fixed creative inventory item count corruption when taking items (some players would see 64x items in the creative inventory after rejoining or changing gamemode). +- Fixed not being able to drop items directly from the creative inventory on mobile. +- Fixed `DataPacketReceiveEvent` not being called for packets sent by `EntityEventBroadcaster`. +- `CreativeInventory::getItem()` and `CreativeInventory::getAll()` now return cloned itemstacks, to prevent accidental modification of the creative inventory. diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 0ac681340..d6464302f 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -32,7 +32,7 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; public const BASE_VERSION = "4.18.3"; - public const IS_DEVELOPMENT_BUILD = true; + public const IS_DEVELOPMENT_BUILD = false; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 9037d5f16b3e00fc1dcdef09883247adda547d4f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 5 Apr 2023 20:07:38 +0100 Subject: [PATCH 09/10] 4.18.4 is next --- src/VersionInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VersionInfo.php b/src/VersionInfo.php index d6464302f..61ec22aec 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -31,8 +31,8 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; - public const BASE_VERSION = "4.18.3"; - public const IS_DEVELOPMENT_BUILD = false; + public const BASE_VERSION = "4.18.4"; + public const IS_DEVELOPMENT_BUILD = true; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 14c1a9550d51bc09fd425a412189941a35fbe3d6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 5 Apr 2023 20:12:21 +0100 Subject: [PATCH 10/10] Update composer dependencies --- composer.json | 2 +- composer.lock | 37 +++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 1bc3c5370..1eb2eb866 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "webmozart/path-util": "^2.3" }, "require-dev": { - "phpstan/phpstan": "1.10.7", + "phpstan/phpstan": "1.10.11", "phpstan/phpstan-phpunit": "^1.1.0", "phpstan/phpstan-strict-rules": "^1.2.0", "phpunit/phpunit": "^9.2" diff --git a/composer.lock b/composer.lock index 8d914bb31..17a18e11e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7c779ace575b5ef662eb5a6b0f173418", + "content-hash": "6cd5185a409af08d842a5e41ba3b877b", "packages": [ { "name": "adhocore/json-comment", @@ -1884,16 +1884,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.7", + "version": "1.10.11", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b10ceb526d9607903c5b2673f1fc8775dbe48975" + "reference": "8aa62e6ea8b58ffb650e02940e55a788cbc3fe21" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b10ceb526d9607903c5b2673f1fc8775dbe48975", - "reference": "b10ceb526d9607903c5b2673f1fc8775dbe48975", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8aa62e6ea8b58ffb650e02940e55a788cbc3fe21", + "reference": "8aa62e6ea8b58ffb650e02940e55a788cbc3fe21", "shasum": "" }, "require": { @@ -1942,7 +1942,7 @@ "type": "tidelift" } ], - "time": "2023-03-16T15:24:20+00:00" + "time": "2023-04-04T19:17:42+00:00" }, { "name": "phpstan/phpstan-phpunit", @@ -1998,16 +1998,16 @@ }, { "name": "phpstan/phpstan-strict-rules", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-strict-rules.git", - "reference": "b7dd96a5503919a43b3cd06a2dced9d4252492f2" + "reference": "b21c03d4f6f3a446e4311155f4be9d65048218e6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/b7dd96a5503919a43b3cd06a2dced9d4252492f2", - "reference": "b7dd96a5503919a43b3cd06a2dced9d4252492f2", + "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/b21c03d4f6f3a446e4311155f4be9d65048218e6", + "reference": "b21c03d4f6f3a446e4311155f4be9d65048218e6", "shasum": "" }, "require": { @@ -2041,9 +2041,9 @@ "description": "Extra strict and opinionated rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-strict-rules/issues", - "source": "https://github.com/phpstan/phpstan-strict-rules/tree/1.5.0" + "source": "https://github.com/phpstan/phpstan-strict-rules/tree/1.5.1" }, - "time": "2023-02-21T10:17:10+00:00" + "time": "2023-03-29T14:47:40+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2365,16 +2365,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.5", + "version": "9.6.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "86e761949019ae83f49240b2f2123fb5ab3b2fc5" + "reference": "b65d59a059d3004a040c16a82e07bbdf6cfdd115" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/86e761949019ae83f49240b2f2123fb5ab3b2fc5", - "reference": "86e761949019ae83f49240b2f2123fb5ab3b2fc5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b65d59a059d3004a040c16a82e07bbdf6cfdd115", + "reference": "b65d59a059d3004a040c16a82e07bbdf6cfdd115", "shasum": "" }, "require": { @@ -2447,7 +2447,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.5" + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.6" }, "funding": [ { @@ -2463,7 +2464,7 @@ "type": "tidelift" } ], - "time": "2023-03-09T06:34:10+00:00" + "time": "2023-03-27T11:43:46+00:00" }, { "name": "sebastian/cli-parser",