Drop pocketmine/uuid for ramsey/uuid

This commit is contained in:
Dylan K. Taylor
2021-03-16 23:03:00 +00:00
parent 6d622c4020
commit 72de45f0e9
24 changed files with 374 additions and 183 deletions

View File

@ -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){

View File

@ -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,

View File

@ -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;

View File

@ -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 = [];

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
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{

View File

@ -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;

View File

@ -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{

View File

@ -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;

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;