From 1a2c10e844aa330e5ca99800669313f3deaa4657 Mon Sep 17 00:00:00 2001 From: jasonw_4331 Date: Wed, 2 Aug 2023 13:05:16 -0400 Subject: [PATCH 01/11] World: Fixed getSafeSpawn() not accepting seed positions below y=1 (#5955) this should have been changed during the introduction of y=-64 minimum world height, but it got missed. --- src/world/World.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/World.php b/src/world/World.php index f556d2e1f..b09304742 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2951,7 +2951,7 @@ class World implements ChunkManager{ * @throws WorldException if the terrain is not generated */ public function getSafeSpawn(?Vector3 $spawn = null) : Position{ - if(!($spawn instanceof Vector3) || $spawn->y < 1){ + if(!($spawn instanceof Vector3) || $spawn->y <= $this->minY){ $spawn = $this->getSpawnLocation(); } From 81941ae9e5dbbcfccedafc31f6acf3a258873b45 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Aug 2023 18:05:30 +0100 Subject: [PATCH 02/11] Bump phpunit/phpunit from 10.2.6 to 10.2.7 (#5957) Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 10.2.6 to 10.2.7. - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/10.2.7/ChangeLog-10.2.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/10.2.6...10.2.7) --- updated-dependencies: - dependency-name: phpunit/phpunit dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index a97b576ee..8d65486e7 100644 --- a/composer.lock +++ b/composer.lock @@ -1541,16 +1541,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "10.1.2", + "version": "10.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e" + "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/db1497ec8dd382e82c962f7abbe0320e4882ee4e", - "reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be1fe461fdc917de2a29a452ccf2657d325b443d", + "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d", "shasum": "" }, "require": { @@ -1607,7 +1607,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.2" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.3" }, "funding": [ { @@ -1615,7 +1615,7 @@ "type": "github" } ], - "time": "2023-05-22T09:04:27+00:00" + "time": "2023-07-26T13:45:28+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1861,16 +1861,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.2.6", + "version": "10.2.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd" + "reference": "a215d9ee8bac1733796e4ddff3306811f14414e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c17815c129f133f3019cc18e8d0c8622e6d9bcd", - "reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a215d9ee8bac1733796e4ddff3306811f14414e5", + "reference": "a215d9ee8bac1733796e4ddff3306811f14414e5", "shasum": "" }, "require": { @@ -1895,7 +1895,7 @@ "sebastian/diff": "^5.0", "sebastian/environment": "^6.0", "sebastian/exporter": "^5.0", - "sebastian/global-state": "^6.0", + "sebastian/global-state": "^6.0.1", "sebastian/object-enumerator": "^5.0", "sebastian/recursion-context": "^5.0", "sebastian/type": "^4.0", @@ -1942,7 +1942,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.6" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.7" }, "funding": [ { @@ -1958,7 +1958,7 @@ "type": "tidelift" } ], - "time": "2023-07-17T12:08:28+00:00" + "time": "2023-08-02T06:46:08+00:00" }, { "name": "sebastian/cli-parser", From 35a28300f6c4a83153087cca54bfe2ffa7d9c185 Mon Sep 17 00:00:00 2001 From: ipad54 <63200545+ipad54@users.noreply.github.com> Date: Mon, 7 Aug 2023 13:47:29 +0300 Subject: [PATCH 03/11] Podzol should be affected by silk touch (#5969) --- src/block/Podzol.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/block/Podzol.php b/src/block/Podzol.php index 4eb720573..33285cc0e 100644 --- a/src/block/Podzol.php +++ b/src/block/Podzol.php @@ -27,6 +27,10 @@ use pocketmine\item\Item; class Podzol extends Opaque{ + public function isAffectedBySilkTouch() : bool{ + return true; + } + public function getDropsForCompatibleTool(Item $item) : array{ return [ VanillaBlocks::DIRT()->asItem() From 2e58387a437848e68ccbf76062492dbb83c830d6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Aug 2023 14:55:53 +0100 Subject: [PATCH 04/11] Fixed thread error capture fail in shutdown function the shutdown handler currently isn't called until join(), which sets isKilled to true and stops the error information from being recorded. --- src/thread/CommonThreadPartsTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread/CommonThreadPartsTrait.php b/src/thread/CommonThreadPartsTrait.php index 340ce554d..e7429be9b 100644 --- a/src/thread/CommonThreadPartsTrait.php +++ b/src/thread/CommonThreadPartsTrait.php @@ -124,7 +124,7 @@ trait CommonThreadPartsTrait{ */ protected function onShutdown() : void{ $this->synchronized(function() : void{ - if(!$this->isKilled && $this->crashInfo === null){ + if($this->isTerminated() && $this->crashInfo === null){ $last = error_get_last(); if($last !== null){ //fatal error From 2559d1719f531242a3d010406a4747d74a7239c0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Aug 2023 14:56:54 +0100 Subject: [PATCH 05/11] All pocketmine\thread\Thread now log uncaught exceptions and fatal errors by default --- src/network/mcpe/raklib/RakLibServer.php | 6 +----- src/scheduler/AsyncWorker.php | 5 ----- src/thread/CommonThreadPartsTrait.php | 16 ++++++++++++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/network/mcpe/raklib/RakLibServer.php b/src/network/mcpe/raklib/RakLibServer.php index e59b6971f..e2d6d9a66 100644 --- a/src/network/mcpe/raklib/RakLibServer.php +++ b/src/network/mcpe/raklib/RakLibServer.php @@ -85,6 +85,7 @@ class RakLibServer extends Thread{ gc_enable(); ini_set("display_errors", '1'); ini_set("display_startup_errors", '1'); + \GlobalLogger::set($this->logger); $socket = new ServerSocket($this->address->deserialize()); $manager = new Server( @@ -107,11 +108,6 @@ class RakLibServer extends Thread{ $manager->waitShutdown(); } - protected function onUncaughtException(\Throwable $e) : void{ - parent::onUncaughtException($e); - $this->logger->logException($e); - } - public function getThreadName() : string{ return "RakLib"; } diff --git a/src/scheduler/AsyncWorker.php b/src/scheduler/AsyncWorker.php index b26afc29b..919e3eedc 100644 --- a/src/scheduler/AsyncWorker.php +++ b/src/scheduler/AsyncWorker.php @@ -69,11 +69,6 @@ class AsyncWorker extends Worker{ $this->saveToThreadStore(self::TLS_KEY_NOTIFIER, $this->sleeperEntry->createNotifier()); } - protected function onUncaughtException(\Throwable $e) : void{ - parent::onUncaughtException($e); - $this->logger->logException($e); - } - public function getLogger() : ThreadSafeLogger{ return $this->logger; } diff --git a/src/thread/CommonThreadPartsTrait.php b/src/thread/CommonThreadPartsTrait.php index e7429be9b..f5cd8fe0a 100644 --- a/src/thread/CommonThreadPartsTrait.php +++ b/src/thread/CommonThreadPartsTrait.php @@ -115,6 +115,7 @@ trait CommonThreadPartsTrait{ protected function onUncaughtException(\Throwable $e) : void{ $this->synchronized(function() use ($e) : void{ $this->crashInfo = ThreadCrashInfo::fromThrowable($e, $this->getThreadName()); + \GlobalLogger::get()->logException($e); }); } @@ -128,11 +129,22 @@ trait CommonThreadPartsTrait{ $last = error_get_last(); if($last !== null){ //fatal error - $this->crashInfo = ThreadCrashInfo::fromLastErrorInfo($last, $this->getThreadName()); + $crashInfo = ThreadCrashInfo::fromLastErrorInfo($last, $this->getThreadName()); }else{ //probably misused exit() - $this->crashInfo = ThreadCrashInfo::fromThrowable(new \RuntimeException("Thread crashed without an error - perhaps exit() was called?"), $this->getThreadName()); + $crashInfo = ThreadCrashInfo::fromThrowable(new \RuntimeException("Thread crashed without an error - perhaps exit() was called?"), $this->getThreadName()); } + $this->crashInfo = $crashInfo; + + $lines = []; + //mimic exception printed format + $lines[] = "Fatal error: " . $crashInfo->makePrettyMessage(); + $lines[] = "--- Stack trace ---"; + foreach($crashInfo->getTrace() as $frame){ + $lines[] = " " . $frame->getPrintableFrame(); + } + $lines[] = "--- End of fatal error information ---"; + \GlobalLogger::get()->critical(implode("\n", $lines)); } }); } From 710177ceb5a0a72e9b442331b5b102614ec48335 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Aug 2023 15:10:31 +0100 Subject: [PATCH 06/11] CS this mistake actually hasn't happened for a while --- src/thread/CommonThreadPartsTrait.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/thread/CommonThreadPartsTrait.php b/src/thread/CommonThreadPartsTrait.php index f5cd8fe0a..de2ecbde8 100644 --- a/src/thread/CommonThreadPartsTrait.php +++ b/src/thread/CommonThreadPartsTrait.php @@ -28,6 +28,7 @@ use pocketmine\errorhandler\ErrorToExceptionHandler; use pocketmine\Server; use function error_get_last; use function error_reporting; +use function implode; use function register_shutdown_function; use function set_exception_handler; From c1638ffaabfb8ffad41e530532f7a131db30a8e8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Aug 2023 17:08:13 +0100 Subject: [PATCH 07/11] Ban foreach by-reference at the PHPStan level --- phpstan.neon.dist | 1 + src/permission/PermissionManager.php | 6 +-- .../rules/DisallowForeachByReferenceRule.php | 53 +++++++++++++++++++ .../block/regenerate_consistency_check.php | 4 +- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 tests/phpstan/rules/DisallowForeachByReferenceRule.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b3aeaf4f6..1d72511f7 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,6 +11,7 @@ includes: rules: - pocketmine\phpstan\rules\DisallowEnumComparisonRule + - pocketmine\phpstan\rules\DisallowForeachByReferenceRule - pocketmine\phpstan\rules\UnsafeForeachArrayOfStringRule # - pocketmine\phpstan\rules\ThreadedSupportedTypesRule diff --git a/src/permission/PermissionManager.php b/src/permission/PermissionManager.php index b7e622934..2d8324887 100644 --- a/src/permission/PermissionManager.php +++ b/src/permission/PermissionManager.php @@ -81,9 +81,9 @@ class PermissionManager{ } public function unsubscribeFromAllPermissions(PermissibleInternal $permissible) : void{ - foreach($this->permSubs as $permission => &$subs){ - unset($subs[spl_object_id($permissible)]); - if(count($subs) === 0){ + foreach($this->permSubs as $permission => $subs){ + unset($this->permSubs[$permission][spl_object_id($permissible)]); + if(count($this->permSubs[$permission]) === 0){ unset($this->permSubs[$permission]); } } diff --git a/tests/phpstan/rules/DisallowForeachByReferenceRule.php b/tests/phpstan/rules/DisallowForeachByReferenceRule.php new file mode 100644 index 000000000..79124d328 --- /dev/null +++ b/tests/phpstan/rules/DisallowForeachByReferenceRule.php @@ -0,0 +1,53 @@ + + */ +final class DisallowForeachByReferenceRule implements Rule{ + + public function getNodeType() : string{ + return Foreach_::class; + } + + public function processNode(Node $node, Scope $scope) : array{ + /** @var Foreach_ $node */ + if($node->byRef){ + return [ + RuleErrorBuilder::message("Foreach by-reference is not allowed, because it has surprising behaviour.") + ->tip("If the value variable is used outside of the foreach construct (e.g. in a second foreach), the iterable's contents will be unexpectedly altered.") + ->build() + ]; + } + + return []; + } +} diff --git a/tests/phpunit/block/regenerate_consistency_check.php b/tests/phpunit/block/regenerate_consistency_check.php index 9930c54f0..ac8a1ad9d 100644 --- a/tests/phpunit/block/regenerate_consistency_check.php +++ b/tests/phpunit/block/regenerate_consistency_check.php @@ -24,6 +24,7 @@ declare(strict_types=1); use pocketmine\block\Block; use pocketmine\block\RuntimeBlockStateRegistry; use pocketmine\utils\AssumptionFailedError; +use pocketmine\utils\Utils; require dirname(__DIR__, 3) . '/vendor/autoload.php'; @@ -91,8 +92,9 @@ foreach($new as $stateId => $name){ $newTable[$name][] = $stateId; } ksort($newTable, SORT_STRING); -foreach($newTable as &$stateIds){ +foreach(Utils::stringifyKeys($newTable) as $name => $stateIds){ sort($stateIds, SORT_NUMERIC); + $newTable[$name] = $stateIds; } file_put_contents(__DIR__ . '/block_factory_consistency_check.json', json_encode( From 514fc1ebb5b182c367ac16d3a94bf4594d62d56b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:33:16 +0100 Subject: [PATCH 08/11] Bump phpunit/phpunit from 10.2.7 to 10.3.1 (#5965) Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 10.2.7 to 10.3.1. - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/10.3.1/ChangeLog-10.3.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/10.2.7...10.3.1) --- updated-dependencies: - dependency-name: phpunit/phpunit dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 8d65486e7..0e4d42469 100644 --- a/composer.lock +++ b/composer.lock @@ -1861,16 +1861,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.2.7", + "version": "10.3.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a215d9ee8bac1733796e4ddff3306811f14414e5" + "reference": "d442ce7c4104d5683c12e67e4dcb5058159e9804" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a215d9ee8bac1733796e4ddff3306811f14414e5", - "reference": "a215d9ee8bac1733796e4ddff3306811f14414e5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d442ce7c4104d5683c12e67e4dcb5058159e9804", + "reference": "d442ce7c4104d5683c12e67e4dcb5058159e9804", "shasum": "" }, "require": { @@ -1910,7 +1910,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "10.2-dev" + "dev-main": "10.3-dev" } }, "autoload": { @@ -1942,7 +1942,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.7" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.3.1" }, "funding": [ { @@ -1958,7 +1958,7 @@ "type": "tidelift" } ], - "time": "2023-08-02T06:46:08+00:00" + "time": "2023-08-04T06:48:08+00:00" }, { "name": "sebastian/cli-parser", From 2c74124e2ea9cd419e65a6495c555cca3b9bc806 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Aug 2023 17:43:01 +0100 Subject: [PATCH 09/11] Update composer dependencies --- composer.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 0e4d42469..bdecdb5ed 100644 --- a/composer.lock +++ b/composer.lock @@ -200,16 +200,16 @@ }, { "name": "pocketmine/bedrock-protocol", - "version": "23.0.2+bedrock-1.20.10", + "version": "23.0.3+bedrock-1.20.10", "source": { "type": "git", "url": "https://github.com/pmmp/BedrockProtocol.git", - "reference": "69a309a2dd7dcf3ec8c316385b866397e8c2cbfd" + "reference": "e4157c7af3f91e1b08fe21be171eb73dad7029e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/69a309a2dd7dcf3ec8c316385b866397e8c2cbfd", - "reference": "69a309a2dd7dcf3ec8c316385b866397e8c2cbfd", + "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/e4157c7af3f91e1b08fe21be171eb73dad7029e9", + "reference": "e4157c7af3f91e1b08fe21be171eb73dad7029e9", "shasum": "" }, "require": { @@ -218,8 +218,8 @@ "php": "^8.0", "pocketmine/binaryutils": "^0.2.0", "pocketmine/color": "^0.2.0 || ^0.3.0", - "pocketmine/math": "^0.3.0 || ^0.4.0", - "pocketmine/nbt": "^0.3.0", + "pocketmine/math": "^0.3.0 || ^0.4.0 || ^1.0.0", + "pocketmine/nbt": "^0.3.0 || ^1.0.0", "ramsey/uuid": "^4.1" }, "require-dev": { @@ -241,9 +241,9 @@ "description": "An implementation of the Minecraft: Bedrock Edition protocol in PHP", "support": { "issues": "https://github.com/pmmp/BedrockProtocol/issues", - "source": "https://github.com/pmmp/BedrockProtocol/tree/23.0.2+bedrock-1.20.10" + "source": "https://github.com/pmmp/BedrockProtocol/tree/23.0.3+bedrock-1.20.10" }, - "time": "2023-07-24T15:35:36+00:00" + "time": "2023-08-03T15:30:52+00:00" }, { "name": "pocketmine/binaryutils", From 9c1ab943bc8b2bba6179a04390b40adfc867357f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Aug 2023 17:43:31 +0100 Subject: [PATCH 10/11] Bump ext-pmmpthread min version to 6.0.7 --- composer.json | 2 +- src/PocketMine.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 5cb32d2ac..75f68f89d 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-openssl": "*", "ext-pcre": "*", "ext-phar": "*", - "ext-pmmpthread": "^6.0.4", + "ext-pmmpthread": "^6.0.7", "ext-reflection": "*", "ext-simplexml": "*", "ext-sockets": "*", diff --git a/src/PocketMine.php b/src/PocketMine.php index 2c8ab06de..4c2ff32a7 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -120,8 +120,8 @@ namespace pocketmine { } if(($pmmpthread_version = phpversion("pmmpthread")) !== false){ - if(version_compare($pmmpthread_version, "6.0.4") < 0 || version_compare($pmmpthread_version, "7.0.0") >= 0){ - $messages[] = "pmmpthread ^6.0.4 is required, while you have $pmmpthread_version."; + if(version_compare($pmmpthread_version, "6.0.7") < 0 || version_compare($pmmpthread_version, "7.0.0") >= 0){ + $messages[] = "pmmpthread ^6.0.7 is required, while you have $pmmpthread_version."; } } From dd79d4c463a2190d0ae38b0be562595a4deb7e95 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Aug 2023 17:44:13 +0100 Subject: [PATCH 11/11] Updated build/php submodule to pmmp/PHP-Binaries@ed0bc4d2afafd00f9ee92823c6b1bd66789ce4f2 --- build/php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/php b/build/php index 46604f2f6..ed0bc4d2a 160000 --- a/build/php +++ b/build/php @@ -1 +1 @@ -Subproject commit 46604f2f6a07e3f68a82e4f4d7efdd45629b101e +Subproject commit ed0bc4d2afafd00f9ee92823c6b1bd66789ce4f2