From 901449b0b16bd1d65e87304c4ea915d19bef6044 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 23 Mar 2022 13:47:01 +0000 Subject: [PATCH 1/6] Player: simplify PlayerItemHeldEvent calling on content change the second parameter to this callback is the OLD slots, not the changed slots. This means that ALL slots are included, including empty and unchanged slots. --- src/player/Player.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index da0b03b471..e27b725002 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -335,12 +335,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $this->callDummyItemHeldEvent(); } }, - function(Inventory $unused, array $changedSlots) : void{ + function() : void{ $this->setUsingItem(false); - $heldSlot = $this->inventory->getHeldItemIndex(); - if(isset($changedSlots[$heldSlot])){ - $this->callDummyItemHeldEvent(); - } + $this->callDummyItemHeldEvent(); } )); From c6374b79b0bd081da06abcd0524c3dcb0d4d2761 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 24 Mar 2022 19:46:11 +0000 Subject: [PATCH 2/6] Improve crashdump ergonomics hopefully this will result in less people making useless pastes that don't contain backtraces ... --- src/crash/CrashDumpRenderer.php | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/crash/CrashDumpRenderer.php b/src/crash/CrashDumpRenderer.php index a9f09df9f2..fa1d77e736 100644 --- a/src/crash/CrashDumpRenderer.php +++ b/src/crash/CrashDumpRenderer.php @@ -44,10 +44,11 @@ final class CrashDumpRenderer{ $this->addLine($this->data->general->name . " Crash Dump " . date("D M j H:i:s T Y", (int) $this->data->time)); $this->addLine(); - $this->addLine("Error: " . $this->data->error["message"]); - $this->addLine("File: " . $this->data->error["file"]); - $this->addLine("Line: " . $this->data->error["line"]); - $this->addLine("Type: " . $this->data->error["type"]); + $version = new VersionString($this->data->general->base_version, $this->data->general->is_dev, $this->data->general->build); + $this->addLine($this->data->general->name . " version: " . $version->getFullVersion(true) . " [Protocol " . $this->data->general->protocol . "]"); + $this->addLine("Git commit: " . $this->data->general->git); + $this->addLine("PHP version: " . $this->data->general->php); + $this->addLine("OS: " . $this->data->general->php_os . ", " . $this->data->general->os); if($this->data->plugin_involvement !== CrashDump::PLUGIN_INVOLVEMENT_NONE){ $this->addLine(); @@ -62,30 +63,21 @@ final class CrashDumpRenderer{ } $this->addLine(); - $this->addLine("Code:"); - foreach($this->data->code as $lineNumber => $line){ - $this->addLine("[$lineNumber] $line"); - } - - $this->addLine(); + $this->addLine("Error: " . $this->data->error["message"]); + $this->addLine("File: " . $this->data->error["file"]); + $this->addLine("Line: " . $this->data->error["line"]); + $this->addLine("Type: " . $this->data->error["type"]); $this->addLine("Backtrace:"); foreach($this->data->trace as $line){ $this->addLine($line); } + $this->addLine(); + $this->addLine("Code:"); - $version = new VersionString($this->data->general->base_version, $this->data->general->is_dev, $this->data->general->build); - - $this->addLine($this->data->general->name . " version: " . $version->getFullVersion(true) . " [Protocol " . $this->data->general->protocol . "]"); - $this->addLine("Git commit: " . $this->data->general->git); - $this->addLine("uname -a: " . $this->data->general->uname); - $this->addLine("PHP Version: " . $this->data->general->php); - $this->addLine("Zend version: " . $this->data->general->zend); - $this->addLine("OS: " . $this->data->general->php_os . ", " . $this->data->general->os); - $this->addLine("Composer libraries: "); - foreach(Utils::stringifyKeys($this->data->general->composer_libraries) as $library => $libraryVersion){ - $this->addLine("- $library $libraryVersion"); + foreach($this->data->code as $lineNumber => $line){ + $this->addLine("[$lineNumber] $line"); } if(count($this->data->plugins) > 0){ @@ -95,6 +87,14 @@ final class CrashDumpRenderer{ $this->addLine($p->name . " " . $p->version . " by " . implode(", ", $p->authors) . " for API(s) " . implode(", ", $p->api)); } } + + $this->addLine(); + $this->addLine("uname -a: " . $this->data->general->uname); + $this->addLine("Zend version: " . $this->data->general->zend); + $this->addLine("Composer libraries: "); + foreach(Utils::stringifyKeys($this->data->general->composer_libraries) as $library => $libraryVersion){ + $this->addLine("- $library $libraryVersion"); + } } public function addLine(string $line = "") : void{ From a6cb3313b05fa103ec0b85767e04a6ad9f693149 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 28 Mar 2022 16:34:57 +0100 Subject: [PATCH 3/6] Release 4.2.5 --- changelogs/4.2.md | 22 ++++++++++++++++++++++ src/VersionInfo.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/changelogs/4.2.md b/changelogs/4.2.md index c0c5c02983..1aecd14a67 100644 --- a/changelogs/4.2.md +++ b/changelogs/4.2.md @@ -57,3 +57,25 @@ Released 18th March 2022. ## Fixes - Fixed a crash when handling out-of-bounds meta values on the network. + +# 4.2.5 +Released 28th March 2022. + +## General +- The layout of the human-readable part of crashdumps has been changed in an effort to improve the useful information density. It is hoped that this change will cause more useful information to be provided when people paste crash traces on Discord, since all the most important information is now at the top of the file. + - Version, git hash, PHP version and OS have been moved to the top of the crashdump. + - Backtrace has been moved above code sample. +- Docker images are now built by GitHub Actions (first live test). + +## Technical +- The methods of `Inventory` and `BaseInventory` have been rearranged to improve coherency. + +## Fixes +### API +- Enum members of enums created using `EnumTrait` are now able to have single-character names. +- Registry members of registries created using `RegistryTrait` or `CloningRegistryTrait` now have their names checked for invalid characters. +- `Entity::__construct()` now uses a guard variable to prevent it from being called multiple times unintentionally. This is necessary because `Entity::__construct()` has side effects. +- Fixed `PlayerItemHeldEvent` not being called when the content of the held slot was changed (e.g. replacing the held item via inventory menu). + +### Gameplay +- Reduced the appearance of ghost items in unsupported gameplay scenarios using client prediction information. This fixes, for example, the appearance of ghost items when right-clicking on a filled flower pot. diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 867d135dfb..cfc8c0cd87 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.2.5"; - public const IS_DEVELOPMENT_BUILD = true; + public const IS_DEVELOPMENT_BUILD = false; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 8ea106c0912814f363cce2f82db948cf38857b39 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 28 Mar 2022 16:35:10 +0100 Subject: [PATCH 4/6] 4.2.6 is next --- src/VersionInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VersionInfo.php b/src/VersionInfo.php index cfc8c0cd87..4c526ad92f 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.2.5"; - public const IS_DEVELOPMENT_BUILD = false; + public const BASE_VERSION = "4.2.6"; + public const IS_DEVELOPMENT_BUILD = true; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 194cb1fb841f16f8fb767b59df91acfef605d8f0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 28 Mar 2022 17:12:00 +0100 Subject: [PATCH 5/6] phpstan 1.5.1 --- composer.json | 4 +-- composer.lock | 35 ++++++++++------------ src/thread/ThreadManager.php | 3 ++ src/utils/Internet.php | 1 - tests/phpstan/configs/actual-problems.neon | 15 ---------- tests/phpstan/configs/phpstan-bugs.neon | 5 ---- 6 files changed, 21 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index 841025d54c..d1f46e0492 100644 --- a/composer.json +++ b/composer.json @@ -53,8 +53,8 @@ "webmozart/path-util": "^2.3" }, "require-dev": { - "phpstan/phpstan": "1.4.10", - "phpstan/phpstan-phpunit": "^1.0.0", + "phpstan/phpstan": "1.5.1", + "phpstan/phpstan-phpunit": "^1.1.0", "phpstan/phpstan-strict-rules": "^1.0.0", "phpunit/phpunit": "^9.2" }, diff --git a/composer.lock b/composer.lock index d2541b0d34..4a89b94215 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": "f3800582ad388d0ec2a95dffc3742d8e", + "content-hash": "fca583271e9a38b30ef924da651f7a20", "packages": [ { "name": "adhocore/json-comment", @@ -1906,20 +1906,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.4.10", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "898c479c39caa727bedf4311dd294a8f4e250e72" + "reference": "cc67578d9afd0f5f2545067285613d7a529aefac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/898c479c39caa727bedf4311dd294a8f4e250e72", - "reference": "898c479c39caa727bedf4311dd294a8f4e250e72", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/cc67578d9afd0f5f2545067285613d7a529aefac", + "reference": "cc67578d9afd0f5f2545067285613d7a529aefac", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.2|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -1941,7 +1941,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.4.10" + "source": "https://github.com/phpstan/phpstan/tree/1.5.1" }, "funding": [ { @@ -1961,25 +1961,25 @@ "type": "tidelift" } ], - "time": "2022-03-14T10:25:45+00:00" + "time": "2022-03-28T15:34:48+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "1.0.0", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "9eb88c9f689003a8a2a5ae9e010338ee94dc39b3" + "reference": "09133ce914f1388a8bb8c7f8573aaa3723cff52a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/9eb88c9f689003a8a2a5ae9e010338ee94dc39b3", - "reference": "9eb88c9f689003a8a2a5ae9e010338ee94dc39b3", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/09133ce914f1388a8bb8c7f8573aaa3723cff52a", + "reference": "09133ce914f1388a8bb8c7f8573aaa3723cff52a", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^1.0" + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.5.0" }, "conflict": { "phpunit/phpunit": "<7.0" @@ -1992,9 +1992,6 @@ }, "type": "phpstan-extension", "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - }, "phpstan": { "includes": [ "extension.neon", @@ -2014,9 +2011,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.0.0" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.1.0" }, - "time": "2021-10-14T08:03:54+00:00" + "time": "2022-03-28T09:20:49+00:00" }, { "name": "phpstan/phpstan-strict-rules", diff --git a/src/thread/ThreadManager.php b/src/thread/ThreadManager.php index 2b1ca58ccc..bf39c31a77 100644 --- a/src/thread/ThreadManager.php +++ b/src/thread/ThreadManager.php @@ -64,6 +64,9 @@ class ThreadManager extends \Volatile{ */ public function getAll() : array{ $array = []; + /** + * @var Worker|Thread $thread + */ foreach($this as $key => $thread){ $array[$key] = $thread; } diff --git a/src/utils/Internet.php b/src/utils/Internet.php index 42745b59a1..786695d55b 100644 --- a/src/utils/Internet.php +++ b/src/utils/Internet.php @@ -220,7 +220,6 @@ class Internet{ } if(!is_string($raw)) throw new AssumptionFailedError("curl_exec() should return string|false when CURLOPT_RETURNTRANSFER is set"); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if(!is_int($httpCode)) throw new AssumptionFailedError("curl_getinfo(CURLINFO_HTTP_CODE) always returns int"); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $rawHeaders = substr($raw, 0, $headerSize); $body = substr($raw, $headerSize); diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index b5a6134555..d3776de3d2 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -905,11 +905,6 @@ parameters: count: 1 path: ../../../src/scheduler/TaskScheduler.php - - - message: "#^Method pocketmine\\\\thread\\\\ThreadManager\\:\\:getAll\\(\\) should return array\\ but returns array\\.$#" - count: 1 - path: ../../../src/thread/ThreadManager.php - - message: "#^Cannot access offset string on mixed\\.$#" count: 3 @@ -925,16 +920,6 @@ parameters: count: 1 path: ../../../src/utils/Config.php - - - message: "#^Parameter \\#2 \\$offset of function substr expects int, mixed given\\.$#" - count: 1 - path: ../../../src/utils/Internet.php - - - - message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, mixed given\\.$#" - count: 1 - path: ../../../src/utils/Internet.php - - message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#" count: 1 diff --git a/tests/phpstan/configs/phpstan-bugs.neon b/tests/phpstan/configs/phpstan-bugs.neon index cb5242cd35..5233cf18d2 100644 --- a/tests/phpstan/configs/phpstan-bugs.neon +++ b/tests/phpstan/configs/phpstan-bugs.neon @@ -85,8 +85,3 @@ parameters: count: 2 path: ../../../src/world/format/io/region/RegionLoader.php - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotSame\\(\\) with arguments stdClass, stdClass and 'Cloning registry…' will always evaluate to false\\.$#" - count: 1 - path: ../../phpunit/utils/CloningRegistryTraitTest.php - From 8cc7fb9dd9e03d223095c71d5b9c045f4f799733 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 28 Mar 2022 17:16:35 +0100 Subject: [PATCH 6/6] fix CS --- src/utils/Internet.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/Internet.php b/src/utils/Internet.php index 786695d55b..7facf73b58 100644 --- a/src/utils/Internet.php +++ b/src/utils/Internet.php @@ -32,7 +32,6 @@ use function curl_getinfo; use function curl_init; use function curl_setopt_array; use function explode; -use function is_int; use function is_string; use function preg_match; use function socket_close;