From 72de45f0e9bd72b339627f15cac0d4a366863321 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 16 Mar 2021 23:03:00 +0000 Subject: [PATCH] Drop pocketmine/uuid for ramsey/uuid --- changelogs/4.0-snapshot.md | 7 +- composer.json | 2 +- composer.lock | 378 +++++++++++++----- src/Server.php | 16 +- src/entity/Human.php | 10 +- src/network/mcpe/cache/CraftingDataCache.php | 5 +- .../mcpe/handler/LoginPacketHandler.php | 9 +- src/network/mcpe/protocol/AddPlayerPacket.php | 4 +- .../mcpe/protocol/CraftingEventPacket.php | 4 +- src/network/mcpe/protocol/EmoteListPacket.php | 8 +- .../mcpe/protocol/PlayerSkinPacket.php | 6 +- .../protocol/serializer/PacketSerializer.php | 26 +- .../mcpe/protocol/types/PlayerListEntry.php | 8 +- .../types/command/CommandOriginData.php | 4 +- .../protocol/types/recipe/MultiRecipe.php | 8 +- .../protocol/types/recipe/ShapedRecipe.php | 8 +- .../protocol/types/recipe/ShapelessRecipe.php | 8 +- .../mcpe/protocol/types/skin/SkinData.php | 4 +- src/player/Player.php | 10 +- src/player/PlayerInfo.php | 8 +- src/player/XboxLivePlayerInfo.php | 4 +- src/stats/SendUsageTask.php | 6 +- src/utils/Utils.php | 10 +- src/world/particle/FloatingTextParticle.php | 4 +- 24 files changed, 374 insertions(+), 183 deletions(-) diff --git a/changelogs/4.0-snapshot.md b/changelogs/4.0-snapshot.md index 5948ef572..03addc130 100644 --- a/changelogs/4.0-snapshot.md +++ b/changelogs/4.0-snapshot.md @@ -917,7 +917,12 @@ This version features substantial changes to the network system, improving coher ### Utils - The `Color` class was removed. It's now found as `pocketmine\color\Color` in the [`pocketmine/color`](https://github.com/pmmp/Color) package. -- The `UUID` class was removed. It's now found as `pocketmine\uuid\UUID` in the [`pocketmine/uuid`](https://github.com/pmmp/UUID) package. +- The `UUID` class was removed. [`ramsey/uuid`](https://github.com/ramsey/uuid) version 4.1 is now used instead. + - `UUID::fromData()` can be replaced by `Ramsey\Uuid\Uuid::uuid3()` + - `UUID::fromRandom()` can be replaced by `Ramsey\Uuid\Uuid::uuid4()` + - `UUID::fromBinary()` can be replaced by `Ramsey\Uuid\Uuid::fromBytes()` (use `Ramsey\Uuid\Uuid::isValid()` to check validity) + - `UUID::toBinary()` is replaced by `Ramsey\Uuid\UuidInterface::getBytes()` + - See the documentation at https://uuid.ramsey.dev/en/latest/introduction.html for more information. - `Terminal::hasFormattingCodes()` no longer auto-detects the availability of formatting codes. Instead it's necessary to use `Terminal::init()` with no parameters to initialize, or `true` or `false` to override. - `Config->save()` no longer catches exceptions thrown during emitting to disk. - The following new classes have been added: diff --git a/composer.json b/composer.json index df788c900..2f2e35a1e 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "pocketmine/raklib": "dev-master", "pocketmine/snooze": "^0.1.0", "pocketmine/spl": "dev-master", - "pocketmine/uuid": "^0.1.0", + "ramsey/uuid": "^4.1", "respect/validation": "^2.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 51021c289..9d350331d 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": "07097f47ac43ad9568068ea11d65ad15", + "content-hash": "cef3fa0d56c5b31a25c31b0826406ef9", "packages": [ { "name": "adhocore/json-comment", @@ -54,6 +54,62 @@ }, "time": "2020-01-03T13:51:23+00:00" }, + { + "name": "brick/math", + "version": "0.9.2", + "source": { + "type": "git", + "url": "https://github.com/brick/math.git", + "reference": "dff976c2f3487d42c1db75a3b180e2b9f0e72ce0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/brick/math/zipball/dff976c2f3487d42c1db75a3b180e2b9f0e72ce0", + "reference": "dff976c2f3487d42c1db75a3b180e2b9f0e72ce0", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.0", + "vimeo/psalm": "4.3.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Brick\\Math\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Arbitrary-precision arithmetic library", + "keywords": [ + "Arbitrary-precision", + "BigInteger", + "BigRational", + "arithmetic", + "bigdecimal", + "bignum", + "brick", + "math" + ], + "support": { + "issues": "https://github.com/brick/math/issues", + "source": "https://github.com/brick/math/tree/0.9.2" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/brick/math", + "type": "tidelift" + } + ], + "time": "2021-01-20T22:51:39+00:00" + }, { "name": "fgrosse/phpasn1", "version": "v2.2.0", @@ -755,43 +811,173 @@ "time": "2021-01-15T15:19:34+00:00" }, { - "name": "pocketmine/uuid", - "version": "0.1.1", + "name": "ramsey/collection", + "version": "1.1.3", "source": { "type": "git", - "url": "https://github.com/pmmp/UUID.git", - "reference": "385051ab7919966191d04b0c5c5009639a4b2ba3" + "url": "https://github.com/ramsey/collection.git", + "reference": "28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/UUID/zipball/385051ab7919966191d04b0c5c5009639a4b2ba3", - "reference": "385051ab7919966191d04b0c5c5009639a4b2ba3", + "url": "https://api.github.com/repos/ramsey/collection/zipball/28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1", + "reference": "28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0", - "pocketmine/binaryutils": "^0.1 || dev-master" + "php": "^7.2 || ^8" }, "require-dev": { - "phpstan/phpstan": "0.12.66", - "phpstan/phpstan-strict-rules": "^0.12.2" + "captainhook/captainhook": "^5.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "ergebnis/composer-normalize": "^2.6", + "fakerphp/faker": "^1.5", + "hamcrest/hamcrest-php": "^2", + "jangregor/phpstan-prophecy": "^0.8", + "mockery/mockery": "^1.3", + "phpstan/extension-installer": "^1", + "phpstan/phpstan": "^0.12.32", + "phpstan/phpstan-mockery": "^0.12.5", + "phpstan/phpstan-phpunit": "^0.12.11", + "phpunit/phpunit": "^8.5 || ^9", + "psy/psysh": "^0.10.4", + "slevomat/coding-standard": "^6.3", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.4" }, "type": "library", "autoload": { "psr-4": { - "pocketmine\\uuid\\": "src/" + "Ramsey\\Collection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-3.0" + "MIT" + ], + "authors": [ + { + "name": "Ben Ramsey", + "email": "ben@benramsey.com", + "homepage": "https://benramsey.com" + } + ], + "description": "A PHP 7.2+ library for representing and manipulating collections.", + "keywords": [ + "array", + "collection", + "hash", + "map", + "queue", + "set" ], - "description": "Basic UUID implementation used by PocketMine-MP and related projects", "support": { - "issues": "https://github.com/pmmp/UUID/issues", - "source": "https://github.com/pmmp/UUID/tree/0.1.1" + "issues": "https://github.com/ramsey/collection/issues", + "source": "https://github.com/ramsey/collection/tree/1.1.3" }, - "time": "2021-01-15T00:33:02+00:00" + "funding": [ + { + "url": "https://github.com/ramsey", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/ramsey/collection", + "type": "tidelift" + } + ], + "time": "2021-01-21T17:40:04+00:00" + }, + { + "name": "ramsey/uuid", + "version": "4.1.1", + "source": { + "type": "git", + "url": "https://github.com/ramsey/uuid.git", + "reference": "cd4032040a750077205918c86049aa0f43d22947" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/cd4032040a750077205918c86049aa0f43d22947", + "reference": "cd4032040a750077205918c86049aa0f43d22947", + "shasum": "" + }, + "require": { + "brick/math": "^0.8 || ^0.9", + "ext-json": "*", + "php": "^7.2 || ^8", + "ramsey/collection": "^1.0", + "symfony/polyfill-ctype": "^1.8" + }, + "replace": { + "rhumsaa/uuid": "self.version" + }, + "require-dev": { + "codeception/aspect-mock": "^3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7.0", + "doctrine/annotations": "^1.8", + "goaop/framework": "^2", + "mockery/mockery": "^1.3", + "moontoast/math": "^1.1", + "paragonie/random-lib": "^2", + "php-mock/php-mock-mockery": "^1.3", + "php-mock/php-mock-phpunit": "^2.5", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpbench/phpbench": "^0.17.1", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-mockery": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^8.5", + "psy/psysh": "^0.10.0", + "slevomat/coding-standard": "^6.0", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "3.9.4" + }, + "suggest": { + "ext-bcmath": "Enables faster math with arbitrary-precision integers using BCMath.", + "ext-ctype": "Enables faster processing of character classification using ctype functions.", + "ext-gmp": "Enables faster math with arbitrary-precision integers using GMP.", + "ext-uuid": "Enables the use of PeclUuidTimeGenerator and PeclUuidRandomGenerator.", + "paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter", + "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Ramsey\\Uuid\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP library for generating and working with universally unique identifiers (UUIDs).", + "homepage": "https://github.com/ramsey/uuid", + "keywords": [ + "guid", + "identifier", + "uuid" + ], + "support": { + "issues": "https://github.com/ramsey/uuid/issues", + "rss": "https://github.com/ramsey/uuid/releases.atom", + "source": "https://github.com/ramsey/uuid" + }, + "funding": [ + { + "url": "https://github.com/ramsey", + "type": "github" + } + ], + "time": "2020-08-18T17:17:46+00:00" }, { "name": "respect/stringifier", @@ -976,6 +1162,85 @@ }, "time": "2021-03-02T08:18:52+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.22.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-07T16:49:33+00:00" + }, { "name": "symfony/polyfill-mbstring", "version": "v1.22.1", @@ -3128,85 +3393,6 @@ ], "time": "2020-09-28T06:39:44+00:00" }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.22.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.22-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-01-07T16:49:33+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.0", diff --git a/src/Server.php b/src/Server.php index a65cd5c30..992d19f6f 100644 --- a/src/Server.php +++ b/src/Server.php @@ -92,7 +92,6 @@ use pocketmine\utils\Process; use pocketmine\utils\Terminal; use pocketmine\utils\TextFormat; use pocketmine\utils\Utils; -use pocketmine\uuid\UUID; use pocketmine\world\format\io\WorldProviderManager; use pocketmine\world\format\io\WritableWorldProvider; use pocketmine\world\generator\Generator; @@ -100,6 +99,7 @@ use pocketmine\world\generator\GeneratorManager; use pocketmine\world\generator\normal\Normal; use pocketmine\world\World; use pocketmine\world\WorldManager; +use Ramsey\Uuid\UuidInterface; use function array_shift; use function array_sum; use function base64_encode; @@ -254,7 +254,7 @@ class Server{ /** @var bool */ private $forceLanguage = false; - /** @var UUID */ + /** @var UuidInterface */ private $serverID; /** @var \DynamicClassLoader */ @@ -361,7 +361,7 @@ class Server{ } /** - * @return UUID + * @return UuidInterface */ public function getServerUniqueId(){ return $this->serverID; @@ -637,10 +637,10 @@ class Server{ } /** - * Returns the player online with a UUID equivalent to the specified UUID object, or null if not found + * Returns the player online with a UUID equivalent to the specified UuidInterface object, or null if not found */ - public function getPlayerByUUID(UUID $uuid) : ?Player{ - return $this->getPlayerByRawUUID($uuid->toBinary()); + public function getPlayerByUUID(UuidInterface $uuid) : ?Player{ + return $this->getPlayerByRawUUID($uuid->getBytes()); } public function getConfigGroup() : ServerConfigGroup{ @@ -1540,7 +1540,7 @@ class Server{ foreach($this->playerList as $p){ $p->getNetworkSession()->onPlayerAdded($player); } - $rawUUID = $player->getUniqueId()->toBinary(); + $rawUUID = $player->getUniqueId()->getBytes(); $this->playerList[$rawUUID] = $player; if($this->sendUsageTicker > 0){ @@ -1549,7 +1549,7 @@ class Server{ } public function removeOnlinePlayer(Player $player) : void{ - if(isset($this->playerList[$rawUUID = $player->getUniqueId()->toBinary()])){ + if(isset($this->playerList[$rawUUID = $player->getUniqueId()->getBytes()])){ unset($this->playerList[$rawUUID]); foreach($this->playerList as $p){ $p->getNetworkSession()->onPlayerRemoved($player); diff --git a/src/entity/Human.php b/src/entity/Human.php index 73db86ac3..ee48388e5 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -55,8 +55,9 @@ use pocketmine\network\mcpe\protocol\types\entity\StringMetadataProperty; use pocketmine\network\mcpe\protocol\types\PlayerListEntry; use pocketmine\player\Player; use pocketmine\utils\Limits; -use pocketmine\uuid\UUID; use pocketmine\world\sound\TotemUseSound; +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\UuidInterface; use function array_filter; use function array_key_exists; use function array_merge; @@ -74,7 +75,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ /** @var EnderChestInventory */ protected $enderChestInventory; - /** @var UUID */ + /** @var UuidInterface */ protected $uuid; /** @var Skin */ @@ -113,7 +114,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ ); } - public function getUniqueId() : UUID{ + public function getUniqueId() : UuidInterface{ return $this->uuid; } @@ -203,7 +204,8 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ $this->setNameTag($nameTagTag->getValue()); } - $this->uuid = UUID::fromData((string) $this->getId(), $this->skin->getSkinData(), $this->getNameTag()); + //TODO: use of NIL UUID for namespace is a hack; we should provide a proper UUID for the namespace + $this->uuid = Uuid::uuid3(Uuid::NIL, ((string) $this->getId()) . $this->skin->getSkinData() . $this->getNameTag()); } protected function initEntity(CompoundTag $nbt) : void{ diff --git a/src/network/mcpe/cache/CraftingDataCache.php b/src/network/mcpe/cache/CraftingDataCache.php index 55aa2c1f3..da3c8e18d 100644 --- a/src/network/mcpe/cache/CraftingDataCache.php +++ b/src/network/mcpe/cache/CraftingDataCache.php @@ -35,10 +35,9 @@ use pocketmine\network\mcpe\protocol\types\recipe\ShapelessRecipe as ProtocolSha use pocketmine\timings\Timings; use pocketmine\utils\Binary; use pocketmine\utils\SingletonTrait; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\Uuid; use function array_map; use function spl_object_id; -use function str_repeat; final class CraftingDataCache{ use SingletonTrait; @@ -72,7 +71,7 @@ final class CraftingDataCache{ $pk->cleanRecipes = true; $counter = 0; - $nullUUID = UUID::fromData(str_repeat("\x00", 16)); + $nullUUID = Uuid::fromString(Uuid::NIL); $converter = TypeConverter::getInstance(); foreach($manager->getShapelessRecipes() as $list){ foreach($list as $recipe){ diff --git a/src/network/mcpe/handler/LoginPacketHandler.php b/src/network/mcpe/handler/LoginPacketHandler.php index b9e81b253..b48bad765 100644 --- a/src/network/mcpe/handler/LoginPacketHandler.php +++ b/src/network/mcpe/handler/LoginPacketHandler.php @@ -43,7 +43,7 @@ use pocketmine\player\Player; use pocketmine\player\PlayerInfo; use pocketmine\player\XboxLivePlayerInfo; use pocketmine\Server; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\Uuid; use function is_array; /** @@ -112,11 +112,10 @@ class LoginPacketHandler extends PacketHandler{ return true; } - try{ - $uuid = UUID::fromString($extraData->identity); - }catch(\InvalidArgumentException $e){ - throw BadPacketException::wrap($e, "Failed to parse login UUID"); + if(!Uuid::isValid($extraData->identity)){ + throw new BadPacketException("Invalid login UUID"); } + $uuid = Uuid::fromString($extraData->identity); if($extraData->XUID !== ""){ $playerInfo = new XboxLivePlayerInfo( $extraData->XUID, diff --git a/src/network/mcpe/protocol/AddPlayerPacket.php b/src/network/mcpe/protocol/AddPlayerPacket.php index f5b6adeed..3b1bd7d40 100644 --- a/src/network/mcpe/protocol/AddPlayerPacket.php +++ b/src/network/mcpe/protocol/AddPlayerPacket.php @@ -31,13 +31,13 @@ use pocketmine\network\mcpe\protocol\types\DeviceOS; use pocketmine\network\mcpe\protocol\types\entity\EntityLink; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; use pocketmine\network\mcpe\protocol\types\inventory\ItemStack; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; use function count; class AddPlayerPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::ADD_PLAYER_PACKET; - /** @var UUID */ + /** @var UuidInterface */ public $uuid; /** @var string */ public $username; diff --git a/src/network/mcpe/protocol/CraftingEventPacket.php b/src/network/mcpe/protocol/CraftingEventPacket.php index e2dd9bddc..e49893869 100644 --- a/src/network/mcpe/protocol/CraftingEventPacket.php +++ b/src/network/mcpe/protocol/CraftingEventPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\inventory\ItemStack; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; use function count; class CraftingEventPacket extends DataPacket implements ServerboundPacket{ @@ -37,7 +37,7 @@ class CraftingEventPacket extends DataPacket implements ServerboundPacket{ public $windowId; /** @var int */ public $type; - /** @var UUID */ + /** @var UuidInterface */ public $id; /** @var ItemStack[] */ public $input = []; diff --git a/src/network/mcpe/protocol/EmoteListPacket.php b/src/network/mcpe/protocol/EmoteListPacket.php index 1847d9211..f6872eac2 100644 --- a/src/network/mcpe/protocol/EmoteListPacket.php +++ b/src/network/mcpe/protocol/EmoteListPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; use function count; class EmoteListPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ @@ -34,11 +34,11 @@ class EmoteListPacket extends DataPacket implements ClientboundPacket, Serverbou /** @var int */ private $playerEntityRuntimeId; - /** @var UUID[] */ + /** @var UuidInterface[] */ private $emoteIds; /** - * @param UUID[] $emoteIds + * @param UuidInterface[] $emoteIds */ public static function create(int $playerEntityRuntimeId, array $emoteIds) : self{ $result = new self; @@ -49,7 +49,7 @@ class EmoteListPacket extends DataPacket implements ClientboundPacket, Serverbou public function getPlayerEntityRuntimeId() : int{ return $this->playerEntityRuntimeId; } - /** @return UUID[] */ + /** @return UuidInterface[] */ public function getEmoteIds() : array{ return $this->emoteIds; } protected function decodePayload(PacketSerializer $in) : void{ diff --git a/src/network/mcpe/protocol/PlayerSkinPacket.php b/src/network/mcpe/protocol/PlayerSkinPacket.php index f97e783e3..3b688e46a 100644 --- a/src/network/mcpe/protocol/PlayerSkinPacket.php +++ b/src/network/mcpe/protocol/PlayerSkinPacket.php @@ -27,12 +27,12 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\skin\SkinData; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; class PlayerSkinPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::PLAYER_SKIN_PACKET; - /** @var UUID */ + /** @var UuidInterface */ public $uuid; /** @var string */ public $oldSkinName = ""; @@ -41,7 +41,7 @@ class PlayerSkinPacket extends DataPacket implements ClientboundPacket, Serverbo /** @var SkinData */ public $skin; - public static function create(UUID $uuid, SkinData $skinData) : self{ + public static function create(UuidInterface $uuid, SkinData $skinData) : self{ $result = new self; $result->uuid = $uuid; $result->skin = $skinData; diff --git a/src/network/mcpe/protocol/serializer/PacketSerializer.php b/src/network/mcpe/protocol/serializer/PacketSerializer.php index 0d710ca23..239a38ba3 100644 --- a/src/network/mcpe/protocol/serializer/PacketSerializer.php +++ b/src/network/mcpe/protocol/serializer/PacketSerializer.php @@ -60,9 +60,11 @@ use pocketmine\network\mcpe\protocol\types\StructureEditorData; use pocketmine\network\mcpe\protocol\types\StructureSettings; use pocketmine\utils\BinaryDataException; use pocketmine\utils\BinaryStream; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; use function count; use function strlen; +use function strrev; +use function substr; class PacketSerializer extends BinaryStream{ @@ -81,21 +83,17 @@ class PacketSerializer extends BinaryStream{ /** * @throws BinaryDataException */ - public function getUUID() : UUID{ - //This is actually two little-endian longs: UUID Most followed by UUID Least - $part1 = $this->getLInt(); - $part0 = $this->getLInt(); - $part3 = $this->getLInt(); - $part2 = $this->getLInt(); - - return new UUID($part0, $part1, $part2, $part3); + public function getUUID() : UuidInterface{ + //This is two little-endian longs: bytes 7-0 followed by bytes 15-8 + $p1 = strrev($this->get(8)); + $p2 = strrev($this->get(8)); + return \Ramsey\Uuid\Uuid::fromBytes($p1 . $p2); } - public function putUUID(UUID $uuid) : void{ - $this->putLInt($uuid->getPart(1)); - $this->putLInt($uuid->getPart(0)); - $this->putLInt($uuid->getPart(3)); - $this->putLInt($uuid->getPart(2)); + public function putUUID(UuidInterface $uuid) : void{ + $bytes = $uuid->getBytes(); + $this->put(strrev(substr($bytes, 0, 8))); + $this->put(strrev(substr($bytes, 8, 8))); } public function getSkin() : SkinData{ diff --git a/src/network/mcpe/protocol/types/PlayerListEntry.php b/src/network/mcpe/protocol/types/PlayerListEntry.php index 9e9aa712b..a50e279b8 100644 --- a/src/network/mcpe/protocol/types/PlayerListEntry.php +++ b/src/network/mcpe/protocol/types/PlayerListEntry.php @@ -24,11 +24,11 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol\types; use pocketmine\network\mcpe\protocol\types\skin\SkinData; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; class PlayerListEntry{ - /** @var UUID */ + /** @var UuidInterface */ public $uuid; /** @var int */ public $entityUniqueId; @@ -47,14 +47,14 @@ class PlayerListEntry{ /** @var bool */ public $isHost = false; - public static function createRemovalEntry(UUID $uuid) : PlayerListEntry{ + public static function createRemovalEntry(UuidInterface $uuid) : PlayerListEntry{ $entry = new PlayerListEntry(); $entry->uuid = $uuid; return $entry; } - public static function createAdditionEntry(UUID $uuid, int $entityUniqueId, string $username, SkinData $skinData, string $xboxUserId = "", string $platformChatId = "", int $buildPlatform = -1, bool $isTeacher = false, bool $isHost = false) : PlayerListEntry{ + public static function createAdditionEntry(UuidInterface $uuid, int $entityUniqueId, string $username, SkinData $skinData, string $xboxUserId = "", string $platformChatId = "", int $buildPlatform = -1, bool $isTeacher = false, bool $isHost = false) : PlayerListEntry{ $entry = new PlayerListEntry(); $entry->uuid = $uuid; $entry->entityUniqueId = $entityUniqueId; diff --git a/src/network/mcpe/protocol/types/command/CommandOriginData.php b/src/network/mcpe/protocol/types/command/CommandOriginData.php index ffea4a4fd..576a80112 100644 --- a/src/network/mcpe/protocol/types/command/CommandOriginData.php +++ b/src/network/mcpe/protocol/types/command/CommandOriginData.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol\types\command; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; class CommandOriginData{ public const ORIGIN_PLAYER = 0; @@ -41,7 +41,7 @@ class CommandOriginData{ /** @var int */ public $type; - /** @var UUID */ + /** @var UuidInterface */ public $uuid; /** @var string */ diff --git a/src/network/mcpe/protocol/types/recipe/MultiRecipe.php b/src/network/mcpe/protocol/types/recipe/MultiRecipe.php index af07d63c0..52b5276eb 100644 --- a/src/network/mcpe/protocol/types/recipe/MultiRecipe.php +++ b/src/network/mcpe/protocol/types/recipe/MultiRecipe.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol\types\recipe; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; final class MultiRecipe extends RecipeWithTypeId{ @@ -41,18 +41,18 @@ final class MultiRecipe extends RecipeWithTypeId{ public const TYPE_FIREWORKS = "00000000-0000-0000-0000-000000000002"; public const TYPE_MAP_LOCKING_CARTOGRAPHY = "602234E4-CAC1-4353-8BB7-B1EBFF70024B"; - /** @var UUID */ + /** @var UuidInterface */ private $recipeId; /** @var int */ private $recipeNetId; - public function __construct(int $typeId, UUID $recipeId, int $recipeNetId){ + public function __construct(int $typeId, UuidInterface $recipeId, int $recipeNetId){ parent::__construct($typeId); $this->recipeId = $recipeId; $this->recipeNetId = $recipeNetId; } - public function getRecipeId() : UUID{ + public function getRecipeId() : UuidInterface{ return $this->recipeId; } diff --git a/src/network/mcpe/protocol/types/recipe/ShapedRecipe.php b/src/network/mcpe/protocol/types/recipe/ShapedRecipe.php index e21ba9163..1a9aee0b8 100644 --- a/src/network/mcpe/protocol/types/recipe/ShapedRecipe.php +++ b/src/network/mcpe/protocol/types/recipe/ShapedRecipe.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol\types\recipe; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\inventory\ItemStack; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; use function count; final class ShapedRecipe extends RecipeWithTypeId{ @@ -36,7 +36,7 @@ final class ShapedRecipe extends RecipeWithTypeId{ private $input; /** @var ItemStack[] */ private $output; - /** @var UUID */ + /** @var UuidInterface */ private $uuid; /** @var string */ private $blockName; @@ -49,7 +49,7 @@ final class ShapedRecipe extends RecipeWithTypeId{ * @param RecipeIngredient[][] $input * @param ItemStack[] $output */ - public function __construct(int $typeId, string $recipeId, array $input, array $output, UUID $uuid, string $blockType, int $priority, int $recipeNetId){ + public function __construct(int $typeId, string $recipeId, array $input, array $output, UuidInterface $uuid, string $blockType, int $priority, int $recipeNetId){ parent::__construct($typeId); $rows = count($input); if($rows < 1 or $rows > 3){ @@ -98,7 +98,7 @@ final class ShapedRecipe extends RecipeWithTypeId{ return $this->output; } - public function getUuid() : UUID{ + public function getUuid() : UuidInterface{ return $this->uuid; } diff --git a/src/network/mcpe/protocol/types/recipe/ShapelessRecipe.php b/src/network/mcpe/protocol/types/recipe/ShapelessRecipe.php index 58903e468..0facbab7c 100644 --- a/src/network/mcpe/protocol/types/recipe/ShapelessRecipe.php +++ b/src/network/mcpe/protocol/types/recipe/ShapelessRecipe.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol\types\recipe; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\inventory\ItemStack; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; use function count; final class ShapelessRecipe extends RecipeWithTypeId{ @@ -36,7 +36,7 @@ final class ShapelessRecipe extends RecipeWithTypeId{ private $inputs; /** @var ItemStack[] */ private $outputs; - /** @var UUID */ + /** @var UuidInterface */ private $uuid; /** @var string */ private $blockName; @@ -49,7 +49,7 @@ final class ShapelessRecipe extends RecipeWithTypeId{ * @param RecipeIngredient[] $inputs * @param ItemStack[] $outputs */ - public function __construct(int $typeId, string $recipeId, array $inputs, array $outputs, UUID $uuid, string $blockName, int $priority, int $recipeNetId){ + public function __construct(int $typeId, string $recipeId, array $inputs, array $outputs, UuidInterface $uuid, string $blockName, int $priority, int $recipeNetId){ parent::__construct($typeId); $this->recipeId = $recipeId; $this->inputs = $inputs; @@ -78,7 +78,7 @@ final class ShapelessRecipe extends RecipeWithTypeId{ return $this->outputs; } - public function getUuid() : UUID{ + public function getUuid() : UuidInterface{ return $this->uuid; } diff --git a/src/network/mcpe/protocol/types/skin/SkinData.php b/src/network/mcpe/protocol/types/skin/SkinData.php index cb281de75..ccc958e89 100644 --- a/src/network/mcpe/protocol/types/skin/SkinData.php +++ b/src/network/mcpe/protocol/types/skin/SkinData.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol\types\skin; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\Uuid; class SkinData{ @@ -86,7 +86,7 @@ class SkinData{ $this->personaCapeOnClassic = $personaCapeOnClassic; $this->capeId = $capeId; //this has to be unique or the client will do stupid things - $this->fullSkinId = $fullSkinId ?? UUID::fromRandom()->toString(); + $this->fullSkinId = $fullSkinId ?? Uuid::uuid4()->toString(); $this->armSize = $armSize; $this->skinColor = $skinColor; $this->personaPieces = $personaPieces; diff --git a/src/player/Player.php b/src/player/Player.php index ec69add5c..c6f7e74f3 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -101,7 +101,6 @@ use pocketmine\permission\PermissibleDelegateTrait; use pocketmine\Server; use pocketmine\timings\Timings; use pocketmine\utils\TextFormat; -use pocketmine\uuid\UUID; use pocketmine\world\ChunkListener; use pocketmine\world\ChunkListenerNoOpTrait; use pocketmine\world\format\Chunk; @@ -110,6 +109,7 @@ use pocketmine\world\sound\EntityAttackNoDamageSound; use pocketmine\world\sound\EntityAttackSound; use pocketmine\world\sound\FireExtinguishSound; use pocketmine\world\World; +use Ramsey\Uuid\UuidInterface; use function abs; use function assert; use function count; @@ -397,7 +397,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ * as SimpleAuth for authentication. This is NOT SAFE anymore as this UUID is now what was given by the client, NOT * a server-computed UUID.) */ - public function getUniqueId() : UUID{ + public function getUniqueId() : UuidInterface{ return parent::getUniqueId(); } @@ -471,14 +471,14 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ } public function canSee(Player $player) : bool{ - return !isset($this->hiddenPlayers[$player->getUniqueId()->toBinary()]); + return !isset($this->hiddenPlayers[$player->getUniqueId()->getBytes()]); } public function hidePlayer(Player $player) : void{ if($player === $this){ return; } - $this->hiddenPlayers[$player->getUniqueId()->toBinary()] = true; + $this->hiddenPlayers[$player->getUniqueId()->getBytes()] = true; $player->despawnFrom($this); } @@ -486,7 +486,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ if($player === $this){ return; } - unset($this->hiddenPlayers[$player->getUniqueId()->toBinary()]); + unset($this->hiddenPlayers[$player->getUniqueId()->getBytes()]); if($player->isOnline()){ $player->spawnTo($this); } diff --git a/src/player/PlayerInfo.php b/src/player/PlayerInfo.php index 787042e80..ca1df8cf6 100644 --- a/src/player/PlayerInfo.php +++ b/src/player/PlayerInfo.php @@ -25,7 +25,7 @@ namespace pocketmine\player; use pocketmine\entity\Skin; use pocketmine\utils\TextFormat; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; /** * Encapsulates data needed to create a player. @@ -34,7 +34,7 @@ class PlayerInfo{ /** @var string */ private $username; - /** @var UUID */ + /** @var UuidInterface */ private $uuid; /** @var Skin */ private $skin; @@ -50,7 +50,7 @@ class PlayerInfo{ * @param mixed[] $extraData * @phpstan-param array $extraData */ - public function __construct(string $username, UUID $uuid, Skin $skin, string $locale, array $extraData = []){ + public function __construct(string $username, UuidInterface $uuid, Skin $skin, string $locale, array $extraData = []){ $this->username = TextFormat::clean($username); $this->uuid = $uuid; $this->skin = $skin; @@ -62,7 +62,7 @@ class PlayerInfo{ return $this->username; } - public function getUuid() : UUID{ + public function getUuid() : UuidInterface{ return $this->uuid; } diff --git a/src/player/XboxLivePlayerInfo.php b/src/player/XboxLivePlayerInfo.php index a0e3a2cbc..94dcc75ae 100644 --- a/src/player/XboxLivePlayerInfo.php +++ b/src/player/XboxLivePlayerInfo.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\player; use pocketmine\entity\Skin; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\UuidInterface; /** * Encapsulates player info specific to players who are authenticated with XBOX Live. @@ -34,7 +34,7 @@ final class XboxLivePlayerInfo extends PlayerInfo{ /** @var string */ private $xuid; - public function __construct(string $xuid, string $username, UUID $uuid, Skin $skin, string $locale, array $extraData = []){ + public function __construct(string $xuid, string $username, UuidInterface $uuid, Skin $skin, string $locale, array $extraData = []){ parent::__construct($username, $uuid, $skin, $locale, $extraData); $this->xuid = $xuid; } diff --git a/src/stats/SendUsageTask.php b/src/stats/SendUsageTask.php index 4fe3394df..c29eb60bc 100644 --- a/src/stats/SendUsageTask.php +++ b/src/stats/SendUsageTask.php @@ -31,8 +31,8 @@ use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\Internet; use pocketmine\utils\Process; use pocketmine\utils\Utils; -use pocketmine\uuid\UUID; use pocketmine\VersionInfo; +use Ramsey\Uuid\Uuid; use function array_map; use function array_values; use function count; @@ -65,7 +65,7 @@ class SendUsageTask extends AsyncTask{ $data = []; $data["uniqueServerId"] = $server->getServerUniqueId()->toString(); $data["uniqueMachineId"] = Utils::getMachineUniqueId()->toString(); - $data["uniqueRequestId"] = UUID::fromData($server->getServerUniqueId()->toString(), microtime(false))->toString(); + $data["uniqueRequestId"] = Uuid::uuid3($server->getServerUniqueId()->toString(), microtime(false))->toString(); switch($type){ case self::TYPE_OPEN: @@ -127,7 +127,7 @@ class SendUsageTask extends AsyncTask{ $playerList[$k] = md5($v); } - $players = array_map(function(Player $p) : string{ return md5($p->getUniqueId()->toBinary()); }, $server->getOnlinePlayers()); + $players = array_map(function(Player $p) : string{ return md5($p->getUniqueId()->getBytes()); }, $server->getOnlinePlayers()); $data["players"] = [ "count" => count($players), diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 0772bac27..af4d22248 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -28,7 +28,8 @@ declare(strict_types=1); namespace pocketmine\utils; use DaveRandom\CallbackValidator\CallbackType; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\UuidInterface; use function array_combine; use function array_map; use function array_reverse; @@ -93,7 +94,7 @@ final class Utils{ /** @var string|null */ private static $os; - /** @var UUID|null */ + /** @var UuidInterface|null */ private static $serverUniqueId = null; /** @@ -178,7 +179,7 @@ final class Utils{ * * @param string $extra optional, additional data to identify the machine */ - public static function getMachineUniqueId(string $extra = "") : UUID{ + public static function getMachineUniqueId(string $extra = "") : UuidInterface{ if(self::$serverUniqueId !== null and $extra === ""){ return self::$serverUniqueId; } @@ -234,7 +235,8 @@ final class Utils{ $data .= $ext . ":" . phpversion($ext); } - $uuid = UUID::fromData($machine, $data); + //TODO: use of NIL as namespace is a hack; it works for now, but we should have a proper namespace UUID + $uuid = Uuid::uuid3(Uuid::NIL, $data); if($extra === ""){ self::$serverUniqueId = $uuid; diff --git a/src/world/particle/FloatingTextParticle.php b/src/world/particle/FloatingTextParticle.php index bca601389..b2caf0606 100644 --- a/src/world/particle/FloatingTextParticle.php +++ b/src/world/particle/FloatingTextParticle.php @@ -36,7 +36,7 @@ use pocketmine\network\mcpe\protocol\types\entity\FloatMetadataProperty; use pocketmine\network\mcpe\protocol\types\entity\LongMetadataProperty; use pocketmine\network\mcpe\protocol\types\inventory\ItemStack; use pocketmine\network\mcpe\protocol\types\PlayerListEntry; -use pocketmine\uuid\UUID; +use Ramsey\Uuid\Uuid; use function str_repeat; class FloatingTextParticle implements Particle{ @@ -90,7 +90,7 @@ class FloatingTextParticle implements Particle{ } if(!$this->invisible){ - $uuid = UUID::fromRandom(); + $uuid = Uuid::uuid4(); $name = $this->title . ($this->text !== "" ? "\n" . $this->text : ""); $p[] = PlayerListPacket::add([PlayerListEntry::createAdditionEntry($uuid, $this->entityId, $name, SkinAdapterSingleton::get()->toSkinData(new Skin("Standard_Custom", str_repeat("\x00", 8192))))]);