From 58d5126adaeb803ab0a4ec903de8f4d2322e7034 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 24 Mar 2023 13:29:33 +0000 Subject: [PATCH 1/4] InventoryManager: fixed crashes when setting contents or slots of inventories during InventoryCloseEvent (and other similar logic) --- src/network/mcpe/InventoryManager.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/network/mcpe/InventoryManager.php b/src/network/mcpe/InventoryManager.php index 0222d6d40..35a45956b 100644 --- a/src/network/mcpe/InventoryManager.php +++ b/src/network/mcpe/InventoryManager.php @@ -407,8 +407,13 @@ class InventoryManager{ } public function onSlotChange(Inventory $inventory, int $slot) : void{ + $inventoryEntry = $this->inventories[spl_object_id($inventory)] ?? null; + if($inventoryEntry === null){ + //this can happen when an inventory changed during InventoryCloseEvent, or when a temporary inventory + //is cleared before removal. + return; + } $currentItem = TypeConverter::getInstance()->coreItemStackToNet($inventory->getItem($slot)); - $inventoryEntry = $this->inventories[spl_object_id($inventory)]; $clientSideItem = $inventoryEntry->predictions[$slot] ?? null; if($clientSideItem === null || !$clientSideItem->equals($currentItem)){ //no prediction or incorrect - do not associate this with the currently active itemstack request @@ -469,7 +474,12 @@ class InventoryManager{ } public function syncContents(Inventory $inventory) : void{ - $entry = $this->inventories[spl_object_id($inventory)]; + $entry = $this->inventories[spl_object_id($inventory)] ?? null; + if($entry === null){ + //this can happen when an inventory changed during InventoryCloseEvent, or when a temporary inventory + //is cleared before removal. + return; + } if($entry->complexSlotMap !== null){ $windowId = ContainerIds::UI; }else{ From dd37b531adf711520ac28f223aeebda435f44e5d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 24 Mar 2023 14:02:23 +0000 Subject: [PATCH 2/4] CONTRIBUTING.md: document network API policy --- CONTRIBUTING.md | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 44b5be106..293d2f436 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,21 +21,22 @@ Larger contributions like feature additions should be preceded by a [Change Prop ## Choosing a target branch PocketMine-MP has three primary branches of development. -| Type of change | `stable` | `minor-next` | `major-next` | -|:---------------|:--------:|:------------:|:------------:| -| Bug fixes | ✔️ | ✔️ | ✔️ | -| Improvements to API docs | ✔️ | ✔️ | ✔️ | -| Cleaning up code | ❌ | ✔️ | ✔️ | -| Changing code formatting or style | ❌ | ✔️ | ✔️ | -| Addition of new core features | ❌ | 🟡 Only if non-disruptive | ✔️ | -| Changing core behaviour (e.g. making something use threads) | ❌ | ✔️ | ✔️ | -| Addition of new configuration options | ❌ | 🟡 Only if optional | ✔️ | -| Addition of new API classes, methods or constants | ❌ | ✔️ | ✔️ | -| Deprecating API classes, methods or constants | ❌ | ✔️ | ✔️ | -| Adding optional parameters to an API method | ❌ | ✔️ | ✔️ | -| Changing API behaviour | ❌ | 🟡 Only if backwards-compatible | ✔️ | -| Removal of API | ❌ | ❌ | ✔️ | -| Backwards-incompatible API change (e.g. renaming a method) | ❌ | ❌ | ✔️ | +| Type of change | `stable` | `minor-next` | `major-next` | +|:--------------------------------------------------------------------------------------------|:--------:|:-------------------------------:|:------------:| +| Bug fixes | ✔️ | ✔️ | ✔️ | +| Improvements to API docs | ✔️ | ✔️ | ✔️ | +| Cleaning up code | ❌ | ✔️ | ✔️ | +| Changing code formatting or style | ❌ | ✔️ | ✔️ | +| Addition of new core features | ❌ | 🟡 Only if non-disruptive | ✔️ | +| Changing core behaviour (e.g. making something use threads) | ❌ | ✔️ | ✔️ | +| Addition of new configuration options | ❌ | 🟡 Only if optional | ✔️ | +| Addition of new API classes, methods or constants | ❌ | ✔️ | ✔️ | +| Deprecating API classes, methods or constants | ❌ | ✔️ | ✔️ | +| Adding optional parameters to an API method | ❌ | ✔️ | ✔️ | +| Changing API behaviour | ❌ | 🟡 Only if backwards-compatible | ✔️ | +| Removal of API | ❌ | ❌ | ✔️ | +| Backwards-incompatible API change (e.g. renaming a method) | ❌ | ❌ | ✔️ | +| Backwards-incompatible internals change (e.g. changing things in `pocketmine\network\mcpe`) | ❌ | ✔️ | ✔️ | ### Notes - **Non-disruptive** means that usage should not be significantly altered by the change. @@ -43,6 +44,9 @@ PocketMine-MP has three primary branches of development. - Examples of **disruptive** changes include changing the way the server is run, world format changes (since those require downtime for the user to convert their world). - **API** includes all public and protected classes, functions and constants (unless marked as `@internal`). - Private members are not part of the API, **unless in a trait**. +- Minecraft's protocol changes are considered necessary internal changes, and are **not** subject to the same rules. + - Protocol changes must always be released in a new minor version, since they disrupt user experience by requiring a client update. +- BC-breaking changes to the internal network API are allowed, but only in new minor versions. This ensures that plugins which use the internal network API will not break (though they shouldn't use such API anyway). ## Making a pull request The basic procedure to create a pull request is: From 289c0b08f4621b939bdb4d471c57aa96319e1247 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 24 Mar 2023 14:06:25 +0000 Subject: [PATCH 3/4] Explicitly state that pocketmine\network\mcpe is an internal package --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 293d2f436..45841fc15 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,6 +44,7 @@ PocketMine-MP has three primary branches of development. - Examples of **disruptive** changes include changing the way the server is run, world format changes (since those require downtime for the user to convert their world). - **API** includes all public and protected classes, functions and constants (unless marked as `@internal`). - Private members are not part of the API, **unless in a trait**. + - The `pocketmine\network\mcpe` package is considered implicitly `@internal` in its entirety (see its [README](src/network/mcpe/README.md) for more details). - Minecraft's protocol changes are considered necessary internal changes, and are **not** subject to the same rules. - Protocol changes must always be released in a new minor version, since they disrupt user experience by requiring a client update. - BC-breaking changes to the internal network API are allowed, but only in new minor versions. This ensures that plugins which use the internal network API will not break (though they shouldn't use such API anyway). From 6f02b83a26d13abff82df9a44e9376cff04dc34d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 25 Mar 2023 20:26:50 +0000 Subject: [PATCH 4/4] Update composer dependencies --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 3305ea5b1..5de16dab9 100644 --- a/composer.lock +++ b/composer.lock @@ -1946,16 +1946,16 @@ }, { "name": "phpstan/phpstan-phpunit", - "version": "1.3.10", + "version": "1.3.11", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "4cc5c6cc38e56bce7ea47c4091814e516d172dc3" + "reference": "9e1b9de6d260461f6e99b6a8f2dbb0bbb98b579c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/4cc5c6cc38e56bce7ea47c4091814e516d172dc3", - "reference": "4cc5c6cc38e56bce7ea47c4091814e516d172dc3", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/9e1b9de6d260461f6e99b6a8f2dbb0bbb98b579c", + "reference": "9e1b9de6d260461f6e99b6a8f2dbb0bbb98b579c", "shasum": "" }, "require": { @@ -1992,9 +1992,9 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.3.10" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.3.11" }, - "time": "2023-03-02T10:25:13+00:00" + "time": "2023-03-25T19:42:13+00:00" }, { "name": "phpstan/phpstan-strict-rules",