From cff2d37add390ba8d17ee931663f980dd86c8092 Mon Sep 17 00:00:00 2001 From: Frago9876543210 Date: Wed, 18 Sep 2019 13:10:42 +0300 Subject: [PATCH 01/19] backport ec0558597b6ca948228846b25751c2b1863cbf3f: CommandParameter: change byte1 field to "flags" (#3115) --- .../network/mcpe/protocol/AvailableCommandsPacket.php | 4 ++-- .../network/mcpe/protocol/types/CommandParameter.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php index e61668c2c..60d56d187 100644 --- a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php @@ -227,7 +227,7 @@ class AvailableCommandsPacket extends DataPacket{ $parameter->paramName = $this->getString(); $parameter->paramType = $this->getLInt(); $parameter->isOptional = $this->getBool(); - $parameter->byte1 = $this->getByte(); + $parameter->flags = $this->getByte(); if($parameter->paramType & self::ARG_FLAG_ENUM){ $index = ($parameter->paramType & 0xffff); @@ -285,7 +285,7 @@ class AvailableCommandsPacket extends DataPacket{ $this->putLInt($type); $this->putBool($parameter->isOptional); - $this->putByte($parameter->byte1); + $this->putByte($parameter->flags); } } } diff --git a/src/pocketmine/network/mcpe/protocol/types/CommandParameter.php b/src/pocketmine/network/mcpe/protocol/types/CommandParameter.php index 2c26ac9bf..b1a00137b 100644 --- a/src/pocketmine/network/mcpe/protocol/types/CommandParameter.php +++ b/src/pocketmine/network/mcpe/protocol/types/CommandParameter.php @@ -31,7 +31,7 @@ class CommandParameter{ /** @var bool */ public $isOptional; /** @var int */ - public $byte1 = 0; //unknown, always zero except for in /gamerule command + public $flags = 0; //shows enum name if 1, always zero except for in /gamerule command /** @var CommandEnum|null */ public $enum; /** @var string|null */ From 7d5c3c9b46ac03a2b97a262759d466b2fc9c3605 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 12 Jun 2019 16:54:30 +0100 Subject: [PATCH 02/19] backport 4364d2a94: AvailableCommandsPacket: Clean up internals this is still disgusting, but it's a little more bearable now. --- .../mcpe/protocol/AvailableCommandsPacket.php | 190 ++++++++++-------- 1 file changed, 102 insertions(+), 88 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php index 60d56d187..41224eb72 100644 --- a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php @@ -29,11 +29,6 @@ use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\protocol\types\CommandData; use pocketmine\network\mcpe\protocol\types\CommandEnum; use pocketmine\network\mcpe\protocol\types\CommandParameter; -use function array_flip; -use function array_keys; -use function array_map; -use function array_search; -use function array_values; use function count; use function dechex; @@ -83,30 +78,6 @@ class AvailableCommandsPacket extends DataPacket{ */ public const ARG_FLAG_POSTFIX = 0x1000000; - /** - * @var string[] - * A list of every single enum value for every single command in the packet, including alias names. - */ - public $enumValues = []; - /** @var int */ - private $enumValuesCount = 0; - - /** - * @var string[] - * A list of argument postfixes. Used for the /xp command's L. - */ - public $postfixes = []; - - /** - * @var CommandEnum[] - * List of command enums, from command aliases to argument enums. - */ - public $enums = []; - /** - * @var int[] string => int map of enum name to index - */ - private $enumMap = []; - /** * @var CommandData[] * List of command data, including name, description, alias indexes and parameters. @@ -121,20 +92,26 @@ class AvailableCommandsPacket extends DataPacket{ public $softEnums = []; protected function decodePayload(){ - for($i = 0, $this->enumValuesCount = $this->getUnsignedVarInt(); $i < $this->enumValuesCount; ++$i){ - $this->enumValues[] = $this->getString(); + /** @var string[] $enumValues */ + $enumValues = []; + for($i = 0, $enumValuesCount = $this->getUnsignedVarInt(); $i < $enumValuesCount; ++$i){ + $enumValues[] = $this->getString(); + } + + /** @var string[] $postfixes */ + $postfixes = []; + for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ + $postfixes[] = $this->getString(); + } + + /** @var CommandEnum[] $enums */ + $enums = []; + for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ + $enums[] = $this->getEnum($enumValues); } for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ - $this->postfixes[] = $this->getString(); - } - - for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ - $this->enums[] = $this->getEnum(); - } - - for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ - $this->commandData[] = $this->getCommandData(); + $this->commandData[] = $this->getCommandData($enums, $postfixes); } for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ @@ -142,17 +119,26 @@ class AvailableCommandsPacket extends DataPacket{ } } - protected function getEnum() : CommandEnum{ + /** + * @param string[] $enumValueList + * + * @return CommandEnum + * @throws \UnexpectedValueException + * @throws BinaryDataException + */ + protected function getEnum(array $enumValueList) : CommandEnum{ $retval = new CommandEnum(); $retval->enumName = $this->getString(); + $listSize = count($enumValueList); + for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ - $index = $this->getEnumValueIndex(); - if(!isset($this->enumValues[$index])){ + $index = $this->getEnumValueIndex($listSize); + if(!isset($enumValueList[$index])){ throw new \UnexpectedValueException("Invalid enum value index $index"); } //Get the enum value from the initial pile of mess - $retval->enumValues[] = $this->enumValues[$index]; + $retval->enumValues[] = $enumValueList[$index]; } return $retval; @@ -170,17 +156,21 @@ class AvailableCommandsPacket extends DataPacket{ return $retval; } - protected function putEnum(CommandEnum $enum){ + /** + * @param CommandEnum $enum + * @param string[] $enumValueMap + */ + protected function putEnum(CommandEnum $enum, array $enumValueMap) : void{ $this->putString($enum->enumName); $this->putUnsignedVarInt(count($enum->enumValues)); + $listSize = count($enumValueMap); foreach($enum->enumValues as $value){ - //Dumb bruteforce search. I hate this packet. - $index = array_search($value, $this->enumValues, true); - if($index === false){ + $index = $enumValueMap[$value] ?? -1; + if($index === -1){ throw new \InvalidStateException("Enum value '$value' not found"); } - $this->putEnumValueIndex($index); + $this->putEnumValueIndex($index, $listSize); } } @@ -193,33 +183,47 @@ class AvailableCommandsPacket extends DataPacket{ } } - protected function getEnumValueIndex() : int{ - if($this->enumValuesCount < 256){ + /** + * @param int $valueCount + * + * @return int + * @throws BinaryDataException + */ + protected function getEnumValueIndex(int $valueCount) : int{ + if($valueCount < 256){ return $this->getByte(); - }elseif($this->enumValuesCount < 65536){ + }elseif($valueCount < 65536){ return $this->getLShort(); }else{ return $this->getLInt(); } } - protected function putEnumValueIndex(int $index){ - if($this->enumValuesCount < 256){ + protected function putEnumValueIndex(int $index, int $valueCount) : void{ + if($valueCount < 256){ $this->putByte($index); - }elseif($this->enumValuesCount < 65536){ + }elseif($valueCount < 65536){ $this->putLShort($index); }else{ $this->putLInt($index); } } - protected function getCommandData() : CommandData{ + /** + * @param CommandEnum[] $enums + * @param string[] $postfixes + * + * @return CommandData + * @throws \UnexpectedValueException + * @throws BinaryDataException + */ + protected function getCommandData(array $enums, array $postfixes) : CommandData{ $retval = new CommandData(); $retval->commandName = $this->getString(); $retval->commandDescription = $this->getString(); $retval->flags = $this->getByte(); $retval->permission = $this->getByte(); - $retval->aliases = $this->enums[$this->getLInt()] ?? null; + $retval->aliases = $enums[$this->getLInt()] ?? null; for($overloadIndex = 0, $overloadCount = $this->getUnsignedVarInt(); $overloadIndex < $overloadCount; ++$overloadIndex){ for($paramIndex = 0, $paramCount = $this->getUnsignedVarInt(); $paramIndex < $paramCount; ++$paramIndex){ @@ -231,13 +235,13 @@ class AvailableCommandsPacket extends DataPacket{ if($parameter->paramType & self::ARG_FLAG_ENUM){ $index = ($parameter->paramType & 0xffff); - $parameter->enum = $this->enums[$index] ?? null; + $parameter->enum = $enums[$index] ?? null; if($parameter->enum === null){ throw new \UnexpectedValueException("deserializing $retval->commandName parameter $parameter->paramName: expected enum at $index, but got none"); } }elseif($parameter->paramType & self::ARG_FLAG_POSTFIX){ $index = ($parameter->paramType & 0xffff); - $parameter->postfix = $this->postfixes[$index] ?? null; + $parameter->postfix = $postfixes[$index] ?? null; if($parameter->postfix === null){ throw new \UnexpectedValueException("deserializing $retval->commandName parameter $parameter->paramName: expected postfix at $index, but got none"); } @@ -252,14 +256,19 @@ class AvailableCommandsPacket extends DataPacket{ return $retval; } - protected function putCommandData(CommandData $data){ + /** + * @param CommandData $data + * @param int[] $enumIndexes string enum name -> int index + * @param int[] $postfixIndexes + */ + protected function putCommandData(CommandData $data, array $enumIndexes, array $postfixIndexes) : void{ $this->putString($data->commandName); $this->putString($data->commandDescription); $this->putByte($data->flags); $this->putByte($data->permission); if($data->aliases !== null){ - $this->putLInt($this->enumMap[$data->aliases->enumName] ?? -1); + $this->putLInt($enumIndexes[$data->aliases->enumName] ?? -1); }else{ $this->putLInt(-1); } @@ -272,10 +281,10 @@ class AvailableCommandsPacket extends DataPacket{ $this->putString($parameter->paramName); if($parameter->enum !== null){ - $type = self::ARG_FLAG_ENUM | self::ARG_FLAG_VALID | ($this->enumMap[$parameter->enum->enumName] ?? -1); + $type = self::ARG_FLAG_ENUM | self::ARG_FLAG_VALID | ($enumIndexes[$parameter->enum->enumName] ?? -1); }elseif($parameter->postfix !== null){ - $key = array_search($parameter->postfix, $this->postfixes, true); - if($key === false){ + $key = $postfixIndexes[$parameter->postfix] ?? -1; + if($key === -1){ throw new \InvalidStateException("Postfix '$parameter->postfix' not in postfixes array"); } $type = self::ARG_FLAG_POSTFIX | $key; @@ -290,7 +299,7 @@ class AvailableCommandsPacket extends DataPacket{ } } - private function argTypeToString(int $argtype) : string{ + private function argTypeToString(int $argtype, array $postfixes) : string{ if($argtype & self::ARG_FLAG_VALID){ if($argtype & self::ARG_FLAG_ENUM){ return "stringenum (" . ($argtype & 0xffff) . ")"; @@ -319,7 +328,7 @@ class AvailableCommandsPacket extends DataPacket{ return "command"; } }elseif($argtype & self::ARG_FLAG_POSTFIX){ - $postfix = $this->postfixes[$argtype & 0xffff]; + $postfix = $postfixes[$argtype & 0xffff]; return "int (postfix $postfix)"; }else{ @@ -330,15 +339,22 @@ class AvailableCommandsPacket extends DataPacket{ } protected function encodePayload(){ - $enumValuesMap = []; - $postfixesMap = []; - $enumMap = []; + /** @var int[] $enumValueIndexes */ + $enumValueIndexes = []; + /** @var int[] $postfixIndexes */ + $postfixIndexes = []; + /** @var int[] $enumIndexes */ + $enumIndexes = []; + /** @var CommandEnum[] $enums */ + $enums = []; foreach($this->commandData as $commandData){ if($commandData->aliases !== null){ - $enumMap[$commandData->aliases->enumName] = $commandData->aliases; + if(!isset($enumIndexes[$commandData->aliases->enumName])){ + $enums[$enumIndexes[$commandData->aliases->enumName] = count($enumIndexes)] = $commandData->aliases; + } foreach($commandData->aliases->enumValues as $str){ - $enumValuesMap[$str] = true; + $enumValueIndexes[$str] = $enumValueIndexes[$str] ?? count($enumValueIndexes); //latest index } } @@ -349,41 +365,39 @@ class AvailableCommandsPacket extends DataPacket{ */ foreach($overload as $parameter){ if($parameter->enum !== null){ - $enumMap[$parameter->enum->enumName] = $parameter->enum; + if(!isset($enumIndexes[$parameter->enum->enumName])){ + $enums[$enumIndexes[$parameter->enum->enumName] = count($enumIndexes)] = $parameter->enum; + } foreach($parameter->enum->enumValues as $str){ - $enumValuesMap[$str] = true; + $enumValueIndexes[$str] = $enumValueIndexes[$str] ?? count($enumValueIndexes); } } if($parameter->postfix !== null){ - $postfixesMap[$parameter->postfix] = true; + $postfixIndexes[$parameter->postfix] = $postfixIndexes[$parameter->postfix] ?? count($postfixIndexes); } } } } - $this->enumValues = array_map('\strval', array_keys($enumValuesMap)); //stupid PHP key casting D: - $this->putUnsignedVarInt($this->enumValuesCount = count($this->enumValues)); - foreach($this->enumValues as $enumValue){ - $this->putString($enumValue); + $this->putUnsignedVarInt(count($enumValueIndexes)); + foreach($enumValueIndexes as $enumValue => $index){ + $this->putString((string) $enumValue); //stupid PHP key casting D: } - $this->postfixes = array_map('\strval', array_keys($postfixesMap)); - $this->putUnsignedVarInt(count($this->postfixes)); - foreach($this->postfixes as $postfix){ - $this->putString($postfix); + $this->putUnsignedVarInt(count($postfixIndexes)); + foreach($postfixIndexes as $postfix => $index){ + $this->putString((string) $postfix); //stupid PHP key casting D: } - $this->enums = array_values($enumMap); - $this->enumMap = array_flip(array_keys($enumMap)); - $this->putUnsignedVarInt(count($this->enums)); - foreach($this->enums as $enum){ - $this->putEnum($enum); + $this->putUnsignedVarInt(count($enums)); + foreach($enums as $enum){ + $this->putEnum($enum, $enumValueIndexes); } $this->putUnsignedVarInt(count($this->commandData)); foreach($this->commandData as $data){ - $this->putCommandData($data); + $this->putCommandData($data, $enumIndexes, $postfixIndexes); } $this->putUnsignedVarInt(count($this->softEnums)); From bb05cfb36c4c7decc23f6a981397a4ed65fd08e2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Oct 2019 15:21:22 +0100 Subject: [PATCH 03/19] Shears: fixed always-false hardness check thanks PHPStan --- src/pocketmine/item/Shears.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/item/Shears.php b/src/pocketmine/item/Shears.php index 04a5b9d55..f2dfb345f 100644 --- a/src/pocketmine/item/Shears.php +++ b/src/pocketmine/item/Shears.php @@ -48,7 +48,7 @@ class Shears extends Tool{ } public function onDestroyBlock(Block $block) : bool{ - if($block->getHardness() === 0 or $block->isCompatibleWithTool($this)){ + if($block->getHardness() === 0.0 or $block->isCompatibleWithTool($this)){ return $this->applyDamage(1); } return false; From f347345bb3e62b810e72bd21ffceb93f69db6968 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Oct 2019 15:25:57 +0100 Subject: [PATCH 04/19] Human::getInventory(): explicitly declare return type the lack of this causes type inference bugs and documentation problems. thanks PHPStan --- src/pocketmine/entity/Human.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index b5fb32263..0a9def938 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -587,6 +587,9 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ return (int) min(100, 7 * $this->getXpLevel()); } + /** + * @return PlayerInventory + */ public function getInventory(){ return $this->inventory; } From 39cc590829dbdcce64f6ecb0953e69d60d93364a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Oct 2019 22:26:48 +0100 Subject: [PATCH 05/19] Skin: accommodate JSON geometry containing comments, closes #3121 --- src/pocketmine/entity/Skin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/entity/Skin.php b/src/pocketmine/entity/Skin.php index 2c66dfaee..d5a1477ea 100644 --- a/src/pocketmine/entity/Skin.php +++ b/src/pocketmine/entity/Skin.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\entity; +use Ahc\Json\Comment as CommentedJsonDecoder; use function implode; use function in_array; -use function json_decode; use function json_encode; use function strlen; @@ -129,7 +129,7 @@ class Skin{ */ public function debloatGeometryData() : void{ if($this->geometryData !== ""){ - $this->geometryData = (string) json_encode(json_decode($this->geometryData)); + $this->geometryData = (string) json_encode((new CommentedJsonDecoder())->decode($this->geometryData)); } } } From c3872619cda36fa6c8fb940a08e974e4d74c2990 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 21 Oct 2019 15:28:20 +0100 Subject: [PATCH 06/19] Block: mark boundingBox as nullable --- src/pocketmine/block/Block.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 5646c8af1..0ed6eb803 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -69,7 +69,7 @@ class Block extends Position implements BlockIds, Metadatable{ /** @var int|null */ protected $itemId; - /** @var AxisAlignedBB */ + /** @var AxisAlignedBB|null */ protected $boundingBox = null; From eda3d9b5e408180787c94b615e18bfaa5612d5ba Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 10:13:47 +0100 Subject: [PATCH 07/19] sync composer dependencies --- composer.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/composer.lock b/composer.lock index 1aa668766..a3eea84d6 100644 --- a/composer.lock +++ b/composer.lock @@ -92,16 +92,16 @@ }, { "name": "pocketmine/binaryutils", - "version": "0.1.9", + "version": "0.1.10", "source": { "type": "git", "url": "https://github.com/pmmp/BinaryUtils.git", - "reference": "8b3b1160679398387cb896fd5d06018413437dfa" + "reference": "435f2ee265bce75ef1aa9563f9b60ff36d705e80" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/BinaryUtils/zipball/8b3b1160679398387cb896fd5d06018413437dfa", - "reference": "8b3b1160679398387cb896fd5d06018413437dfa", + "url": "https://api.github.com/repos/pmmp/BinaryUtils/zipball/435f2ee265bce75ef1aa9563f9b60ff36d705e80", + "reference": "435f2ee265bce75ef1aa9563f9b60ff36d705e80", "shasum": "" }, "require": { @@ -119,23 +119,23 @@ ], "description": "Classes and methods for conveniently handling binary data", "support": { - "source": "https://github.com/pmmp/BinaryUtils/tree/0.1.9", + "source": "https://github.com/pmmp/BinaryUtils/tree/0.1.10", "issues": "https://github.com/pmmp/BinaryUtils/issues" }, - "time": "2019-07-22T13:15:53+00:00" + "time": "2019-10-21T14:40:32+00:00" }, { "name": "pocketmine/math", - "version": "0.2.2", + "version": "0.2.3", "source": { "type": "git", "url": "https://github.com/pmmp/Math.git", - "reference": "b755d3fb7025c4ddb7d9d6df0ba7e0b65125e51c" + "reference": "68be8a79fd0169043ef514797c304517cb8a6071" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/Math/zipball/b755d3fb7025c4ddb7d9d6df0ba7e0b65125e51c", - "reference": "b755d3fb7025c4ddb7d9d6df0ba7e0b65125e51c", + "url": "https://api.github.com/repos/pmmp/Math/zipball/68be8a79fd0169043ef514797c304517cb8a6071", + "reference": "68be8a79fd0169043ef514797c304517cb8a6071", "shasum": "" }, "require": { @@ -153,23 +153,23 @@ ], "description": "PHP library containing math related code used in PocketMine-MP", "support": { - "source": "https://github.com/pmmp/Math/tree/0.2.2", + "source": "https://github.com/pmmp/Math/tree/0.2.3", "issues": "https://github.com/pmmp/Math/issues" }, - "time": "2019-01-04T15:42:36+00:00" + "time": "2019-10-21T14:35:10+00:00" }, { "name": "pocketmine/nbt", - "version": "0.2.10", + "version": "0.2.11", "source": { "type": "git", "url": "https://github.com/pmmp/NBT.git", - "reference": "2db27aebe7dc89772aaa8df53361eef801f60063" + "reference": "78784b93632c51f0fad0719b2d6ffe072529db6d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/NBT/zipball/2db27aebe7dc89772aaa8df53361eef801f60063", - "reference": "2db27aebe7dc89772aaa8df53361eef801f60063", + "url": "https://api.github.com/repos/pmmp/NBT/zipball/78784b93632c51f0fad0719b2d6ffe072529db6d", + "reference": "78784b93632c51f0fad0719b2d6ffe072529db6d", "shasum": "" }, "require": { @@ -194,10 +194,10 @@ ], "description": "PHP library for working with Named Binary Tags", "support": { - "source": "https://github.com/pmmp/NBT/tree/0.2.10", + "source": "https://github.com/pmmp/NBT/tree/0.2.11", "issues": "https://github.com/pmmp/NBT/issues" }, - "time": "2019-07-22T15:22:23+00:00" + "time": "2019-10-21T14:50:43+00:00" }, { "name": "pocketmine/raklib", From f63857deed48149e60c525e8a7f1b0ae53138f8b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 10:15:29 +0100 Subject: [PATCH 08/19] update build/php submodule to pmmp/php-build-scripts@1b3fe3120cac93ef8d821a1c62a3722576fcfd81 --- build/php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/php b/build/php index ffc465f4f..1b3fe3120 160000 --- a/build/php +++ b/build/php @@ -1 +1 @@ -Subproject commit ffc465f4f806269138fc210832500c51fdecd471 +Subproject commit 1b3fe3120cac93ef8d821a1c62a3722576fcfd81 From acaa0e33b0e378d7da9a5bf92bbba96494c2f557 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 10:16:44 +0100 Subject: [PATCH 09/19] update DevTools submodule to pmmp/PocketMine-DevTools@3fadb2c3f45a528a715733ba41c273289ef8ffb1 --- tests/plugins/PocketMine-DevTools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/PocketMine-DevTools b/tests/plugins/PocketMine-DevTools index c0f0f9383..3fadb2c3f 160000 --- a/tests/plugins/PocketMine-DevTools +++ b/tests/plugins/PocketMine-DevTools @@ -1 +1 @@ -Subproject commit c0f0f9383d27d0efb2c1d04ea3678beb6a14d3af +Subproject commit 3fadb2c3f45a528a715733ba41c273289ef8ffb1 From 305c63ba4d19715b8f488136be26f7eeed3c6099 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 10:21:17 +0100 Subject: [PATCH 10/19] MainLogger: initialize shutdown field in the conventional manner this avoids uninitialized uses --- src/pocketmine/utils/MainLogger.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pocketmine/utils/MainLogger.php b/src/pocketmine/utils/MainLogger.php index 7f7615a08..9882392dc 100644 --- a/src/pocketmine/utils/MainLogger.php +++ b/src/pocketmine/utils/MainLogger.php @@ -61,7 +61,7 @@ class MainLogger extends \AttachableThreadedLogger{ /** @var \Threaded */ protected $logStream; /** @var bool */ - protected $shutdown; + protected $shutdown = false; /** @var bool */ protected $logDebug; /** @var MainLogger */ @@ -344,7 +344,6 @@ class MainLogger extends \AttachableThreadedLogger{ } public function run(){ - $this->shutdown = false; $logResource = fopen($this->logFile, "ab"); if(!is_resource($logResource)){ throw new \RuntimeException("Couldn't open log file"); From cc3285c8fe3706ec029015bcdbbd431b586a6c3a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 10:25:24 +0100 Subject: [PATCH 11/19] Chest: fixed type doc of doubleChestInventory field --- src/pocketmine/tile/Chest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 1eb109b0d..f8e57ea19 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -42,7 +42,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ /** @var ChestInventory */ protected $inventory; - /** @var DoubleChestInventory */ + /** @var DoubleChestInventory|null */ protected $doubleInventory = null; /** @var int|null */ From e198c8fa8b053630277b632b1d5c6649772511c0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 10:26:49 +0100 Subject: [PATCH 12/19] Task: mark taskHandler field as nullable --- src/pocketmine/scheduler/Task.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/scheduler/Task.php b/src/pocketmine/scheduler/Task.php index c5851b587..f2ad1d862 100644 --- a/src/pocketmine/scheduler/Task.php +++ b/src/pocketmine/scheduler/Task.php @@ -27,7 +27,7 @@ use pocketmine\utils\Utils; abstract class Task{ - /** @var TaskHandler */ + /** @var TaskHandler|null */ private $taskHandler = null; /** From 43ebb23085290ed41e4b5ccd46f327b71bbebda6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 10:42:22 +0100 Subject: [PATCH 13/19] Permission: remove dead code from loadPermission() --- src/pocketmine/permission/Permission.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pocketmine/permission/Permission.php b/src/pocketmine/permission/Permission.php index 38a3cc132..d1eba9dce 100644 --- a/src/pocketmine/permission/Permission.php +++ b/src/pocketmine/permission/Permission.php @@ -112,12 +112,7 @@ class Permission{ $desc = null; $children = []; if(isset($data["default"])){ - $value = Permission::getByName($data["default"]); - if($value !== null){ - $default = $value; - }else{ - throw new \InvalidStateException("'default' key contained unknown value"); - } + $default = Permission::getByName($data["default"]); } if(isset($data["children"])){ From 77d8f133f1c775ecce2a33a02dc68d8c7da98e85 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 11:54:37 +0100 Subject: [PATCH 14/19] LevelChunkPacket: fixed broken type assert in withCache() --- src/pocketmine/network/mcpe/protocol/LevelChunkPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/network/mcpe/protocol/LevelChunkPacket.php b/src/pocketmine/network/mcpe/protocol/LevelChunkPacket.php index e1d79f2f6..008d26bf3 100644 --- a/src/pocketmine/network/mcpe/protocol/LevelChunkPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelChunkPacket.php @@ -57,7 +57,7 @@ class LevelChunkPacket extends DataPacket/* implements ClientboundPacket*/{ } public static function withCache(int $chunkX, int $chunkZ, int $subChunkCount, array $usedBlobHashes, string $extraPayload) : self{ - (static function(int ...$hashes){})($usedBlobHashes); + (static function(int ...$hashes){})(...$usedBlobHashes); $result = new self; $result->chunkX = $chunkX; $result->chunkZ = $chunkZ; From f0c36f3413f047afc7df6aa6b653c0ebed1164c1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 11:57:04 +0100 Subject: [PATCH 15/19] ClientCacheMissResponsePacket: fix broken type assert in create() ouch! PhpStorm never saw these... --- .../network/mcpe/protocol/ClientCacheMissResponsePacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/network/mcpe/protocol/ClientCacheMissResponsePacket.php b/src/pocketmine/network/mcpe/protocol/ClientCacheMissResponsePacket.php index 456f29419..1118181d1 100644 --- a/src/pocketmine/network/mcpe/protocol/ClientCacheMissResponsePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ClientCacheMissResponsePacket.php @@ -42,7 +42,7 @@ class ClientCacheMissResponsePacket extends DataPacket/* implements ClientboundP */ public static function create(array $blobs) : self{ //type check - (static function(ChunkCacheBlob ...$blobs){})($blobs); + (static function(ChunkCacheBlob ...$blobs){})(...$blobs); $result = new self; $result->blobs = $blobs; From da17ade575273ddfb628ce340f6afcb3923f6010 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 12:23:01 +0100 Subject: [PATCH 16/19] AvailableCommandsPacket: fixed wrong parameter type doc for putEnum() --- .../network/mcpe/protocol/AvailableCommandsPacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php index 41224eb72..89295717e 100644 --- a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php @@ -158,7 +158,7 @@ class AvailableCommandsPacket extends DataPacket{ /** * @param CommandEnum $enum - * @param string[] $enumValueMap + * @param int[] $enumValueMap string enum name -> int index */ protected function putEnum(CommandEnum $enum, array $enumValueMap) : void{ $this->putString($enum->enumName); From 29f002b32c2088a2521a688a843cfb9e1253e916 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 12:23:42 +0100 Subject: [PATCH 17/19] LightUpdate: fixed type doc for updateNodes field --- src/pocketmine/level/light/LightUpdate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/level/light/LightUpdate.php b/src/pocketmine/level/light/LightUpdate.php index 22c7fe18b..a2c4bc45e 100644 --- a/src/pocketmine/level/light/LightUpdate.php +++ b/src/pocketmine/level/light/LightUpdate.php @@ -34,7 +34,7 @@ abstract class LightUpdate{ /** @var ChunkManager */ protected $level; - /** @var int[] blockhash => new light level */ + /** @var int[][] blockhash => [x, y, z, new light level] */ protected $updateNodes = []; /** @var \SplQueue */ From d1b70bd4003b2a1e77c3c7eedbddcf9fc4ec0638 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 14:38:02 +0100 Subject: [PATCH 18/19] Release 3.9.6 --- changelogs/3.9.md | 26 ++++++++++++++++++++++++++ src/pocketmine/VersionInfo.php | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/changelogs/3.9.md b/changelogs/3.9.md index 9e91d7c04..0618aef71 100644 --- a/changelogs/3.9.md +++ b/changelogs/3.9.md @@ -74,3 +74,29 @@ Plugin developers should **only** update their required API to this version if y - Fixed some issues with multiple consecutive commas inside quotes in form responses. - Fixed server crash when the manifest json does not contain a json object in a resource pack. - Ender pearls no longer collide with blocks that do not have any collision boxes. + +# 3.9.6 +- Updated Composer dependencies to their latest versions. +- Prevent clients repeating the resource pack sequence. This fixes error spam with bugged 1.12 clients. +- `Internet::simpleCurl()` now includes the PocketMine-MP version in the user-agent string. +- Spawn protection is now disabled by default in the setup wizard. +- Default difficulty is now NORMAL(2) instead of EASY(1). +- Fixed crashing on corrupted world manifest and unsupported world formats. +- Fixed `/transferserver` being usable without appropriate permissions. +- `RegionLoader->removeChunk()` now writes the region header as appropriate. +- Fixed performance issue when loading large regions (bug in header validation). +- Fixed skin geometry being removed when the JSON contained comments. +- Added new constants to `EventPacket`. +- Added encode/decode for `StructureTemplateDataExportRequestPacket` and `StructureTemplateDataExportResponsePacket`. +- Fixed broken type asserts in `LevelChunkPacket::withCache()` and `ClientCacheMissResponsePacket::create()`. +- `types\CommandParameter` field `byte1` has been renamed to `flags`. +- Cleaned up public interface of `AvailableCommandsPacket`, removing fields which exposed details of the encoding scheme. +- Improved documentation for the following API methods: + - `pocketmine\item\Item`: + - `addCreativeItem()` + - `removeCreativeItem()` + - `clearCreativeItems()` + - `pocketmine\level\Explosion`: + - `explodeA()` + - `explodeB()` +- Fixed various cosmetic documentation inconsistencies in the core and dependencies. \ No newline at end of file diff --git a/src/pocketmine/VersionInfo.php b/src/pocketmine/VersionInfo.php index 2ccede412..08f23277a 100644 --- a/src/pocketmine/VersionInfo.php +++ b/src/pocketmine/VersionInfo.php @@ -23,5 +23,5 @@ namespace pocketmine; const NAME = "PocketMine-MP"; const BASE_VERSION = "3.9.6"; -const IS_DEVELOPMENT_BUILD = true; +const IS_DEVELOPMENT_BUILD = false; const BUILD_NUMBER = 0; From 3d840e969dc8aa54b540cc66a458d4e84f2cb069 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 14:38:02 +0100 Subject: [PATCH 19/19] 3.9.7 is next --- src/pocketmine/VersionInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/VersionInfo.php b/src/pocketmine/VersionInfo.php index 08f23277a..fd7e7bd86 100644 --- a/src/pocketmine/VersionInfo.php +++ b/src/pocketmine/VersionInfo.php @@ -22,6 +22,6 @@ namespace pocketmine; const NAME = "PocketMine-MP"; -const BASE_VERSION = "3.9.6"; -const IS_DEVELOPMENT_BUILD = false; +const BASE_VERSION = "3.9.7"; +const IS_DEVELOPMENT_BUILD = true; const BUILD_NUMBER = 0;