mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-15 07:55:31 +00:00
Move SkinAdapter under TypeConverter, remove SkinAdapterSingleton
this is legacy cruft from PM3, which didn't have TypeConverter or SingletonTrait.
This commit is contained in:
parent
ed11fd5a83
commit
926f68d8c5
@ -46,7 +46,7 @@ use pocketmine\nbt\tag\CompoundTag;
|
|||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\nbt\tag\ListTag;
|
use pocketmine\nbt\tag\ListTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\network\mcpe\convert\SkinAdapterSingleton;
|
use pocketmine\network\mcpe\convert\TypeConverter;
|
||||||
use pocketmine\network\mcpe\EntityEventBroadcaster;
|
use pocketmine\network\mcpe\EntityEventBroadcaster;
|
||||||
use pocketmine\network\mcpe\NetworkBroadcastUtils;
|
use pocketmine\network\mcpe\NetworkBroadcastUtils;
|
||||||
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
|
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
|
||||||
@ -166,7 +166,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
|||||||
*/
|
*/
|
||||||
public function sendSkin(?array $targets = null) : void{
|
public function sendSkin(?array $targets = null) : void{
|
||||||
NetworkBroadcastUtils::broadcastPackets($targets ?? $this->hasSpawned, [
|
NetworkBroadcastUtils::broadcastPackets($targets ?? $this->hasSpawned, [
|
||||||
PlayerSkinPacket::create($this->getUniqueId(), "", "", SkinAdapterSingleton::get()->toSkinData($this->skin))
|
PlayerSkinPacket::create($this->getUniqueId(), "", "", TypeConverter::getInstance()->getSkinAdapter()->toSkinData($this->skin))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,11 +469,11 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
|||||||
|
|
||||||
protected function sendSpawnPacket(Player $player) : void{
|
protected function sendSpawnPacket(Player $player) : void{
|
||||||
$networkSession = $player->getNetworkSession();
|
$networkSession = $player->getNetworkSession();
|
||||||
|
$typeConverter = $networkSession->getTypeConverter();
|
||||||
if(!($this instanceof Player)){
|
if(!($this instanceof Player)){
|
||||||
$networkSession->sendDataPacket(PlayerListPacket::add([PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), SkinAdapterSingleton::get()->toSkinData($this->skin))]));
|
$networkSession->sendDataPacket(PlayerListPacket::add([PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), $typeConverter->getSkinAdapter()->toSkinData($this->skin))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$typeConverter = $networkSession->getTypeConverter();
|
|
||||||
$networkSession->sendDataPacket(AddPlayerPacket::create(
|
$networkSession->sendDataPacket(AddPlayerPacket::create(
|
||||||
$this->getUniqueId(),
|
$this->getUniqueId(),
|
||||||
$this->getName(),
|
$this->getName(),
|
||||||
|
@ -38,7 +38,6 @@ use pocketmine\network\mcpe\cache\ChunkCache;
|
|||||||
use pocketmine\network\mcpe\compression\CompressBatchPromise;
|
use pocketmine\network\mcpe\compression\CompressBatchPromise;
|
||||||
use pocketmine\network\mcpe\compression\Compressor;
|
use pocketmine\network\mcpe\compression\Compressor;
|
||||||
use pocketmine\network\mcpe\compression\DecompressionException;
|
use pocketmine\network\mcpe\compression\DecompressionException;
|
||||||
use pocketmine\network\mcpe\convert\SkinAdapterSingleton;
|
|
||||||
use pocketmine\network\mcpe\convert\TypeConverter;
|
use pocketmine\network\mcpe\convert\TypeConverter;
|
||||||
use pocketmine\network\mcpe\encryption\DecryptionException;
|
use pocketmine\network\mcpe\encryption\DecryptionException;
|
||||||
use pocketmine\network\mcpe\encryption\EncryptionContext;
|
use pocketmine\network\mcpe\encryption\EncryptionContext;
|
||||||
@ -1108,12 +1107,12 @@ class NetworkSession{
|
|||||||
*/
|
*/
|
||||||
public function syncPlayerList(array $players) : void{
|
public function syncPlayerList(array $players) : void{
|
||||||
$this->sendDataPacket(PlayerListPacket::add(array_map(function(Player $player) : PlayerListEntry{
|
$this->sendDataPacket(PlayerListPacket::add(array_map(function(Player $player) : PlayerListEntry{
|
||||||
return PlayerListEntry::createAdditionEntry($player->getUniqueId(), $player->getId(), $player->getDisplayName(), SkinAdapterSingleton::get()->toSkinData($player->getSkin()), $player->getXuid());
|
return PlayerListEntry::createAdditionEntry($player->getUniqueId(), $player->getId(), $player->getDisplayName(), TypeConverter::getInstance()->getSkinAdapter()->toSkinData($player->getSkin()), $player->getXuid());
|
||||||
}, $players)));
|
}, $players)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPlayerAdded(Player $p) : void{
|
public function onPlayerAdded(Player $p) : void{
|
||||||
$this->sendDataPacket(PlayerListPacket::add([PlayerListEntry::createAdditionEntry($p->getUniqueId(), $p->getId(), $p->getDisplayName(), SkinAdapterSingleton::get()->toSkinData($p->getSkin()), $p->getXuid())]));
|
$this->sendDataPacket(PlayerListPacket::add([PlayerListEntry::createAdditionEntry($p->getUniqueId(), $p->getId(), $p->getDisplayName(), TypeConverter::getInstance()->getSkinAdapter()->toSkinData($p->getSkin()), $p->getXuid())]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPlayerRemoved(Player $p) : void{
|
public function onPlayerRemoved(Player $p) : void{
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* ____ _ _ __ __ _ __ __ ____
|
|
||||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
||||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
||||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
||||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* @author PocketMine Team
|
|
||||||
* @link http://www.pocketmine.net/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace pocketmine\network\mcpe\convert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accessor for SkinAdapter
|
|
||||||
*/
|
|
||||||
class SkinAdapterSingleton{
|
|
||||||
private static ?SkinAdapter $skinAdapter = null;
|
|
||||||
|
|
||||||
public static function get() : SkinAdapter{
|
|
||||||
if(self::$skinAdapter === null){
|
|
||||||
self::$skinAdapter = new LegacySkinAdapter();
|
|
||||||
}
|
|
||||||
return self::$skinAdapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function set(SkinAdapter $adapter) : void{
|
|
||||||
self::$skinAdapter = $adapter;
|
|
||||||
}
|
|
||||||
}
|
|
@ -63,6 +63,8 @@ class TypeConverter{
|
|||||||
private ItemTypeDictionary $itemTypeDictionary;
|
private ItemTypeDictionary $itemTypeDictionary;
|
||||||
private int $shieldRuntimeId;
|
private int $shieldRuntimeId;
|
||||||
|
|
||||||
|
private SkinAdapter $skinAdapter;
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
//TODO: inject stuff via constructor
|
//TODO: inject stuff via constructor
|
||||||
$this->blockItemIdMap = BlockItemIdMap::getInstance();
|
$this->blockItemIdMap = BlockItemIdMap::getInstance();
|
||||||
@ -83,6 +85,8 @@ class TypeConverter{
|
|||||||
GlobalItemDataHandlers::getSerializer(),
|
GlobalItemDataHandlers::getSerializer(),
|
||||||
GlobalItemDataHandlers::getDeserializer()
|
GlobalItemDataHandlers::getDeserializer()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->skinAdapter = new LegacySkinAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockTranslator() : BlockTranslator{ return $this->blockTranslator; }
|
public function getBlockTranslator() : BlockTranslator{ return $this->blockTranslator; }
|
||||||
@ -91,6 +95,12 @@ class TypeConverter{
|
|||||||
|
|
||||||
public function getItemTranslator() : ItemTranslator{ return $this->itemTranslator; }
|
public function getItemTranslator() : ItemTranslator{ return $this->itemTranslator; }
|
||||||
|
|
||||||
|
public function getSkinAdapter() : SkinAdapter{ return $this->skinAdapter; }
|
||||||
|
|
||||||
|
public function setSkinAdapter(SkinAdapter $skinAdapter) : void{
|
||||||
|
$this->skinAdapter = $skinAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a client-friendly gamemode of the specified real gamemode
|
* Returns a client-friendly gamemode of the specified real gamemode
|
||||||
* This function takes care of handling gamemodes known to MCPE (as of 1.1.0.3, that includes Survival, Creative and Adventure)
|
* This function takes care of handling gamemodes known to MCPE (as of 1.1.0.3, that includes Survival, Creative and Adventure)
|
||||||
|
@ -45,7 +45,6 @@ use pocketmine\math\Facing;
|
|||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\network\mcpe\convert\SkinAdapterSingleton;
|
|
||||||
use pocketmine\network\mcpe\InventoryManager;
|
use pocketmine\network\mcpe\InventoryManager;
|
||||||
use pocketmine\network\mcpe\NetworkSession;
|
use pocketmine\network\mcpe\NetworkSession;
|
||||||
use pocketmine\network\mcpe\protocol\ActorEventPacket;
|
use pocketmine\network\mcpe\protocol\ActorEventPacket;
|
||||||
@ -837,7 +836,7 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
|
|
||||||
$this->session->getLogger()->debug("Processing skin change request");
|
$this->session->getLogger()->debug("Processing skin change request");
|
||||||
try{
|
try{
|
||||||
$skin = SkinAdapterSingleton::get()->fromSkinData($packet->skin);
|
$skin = $this->session->getTypeConverter()->getSkinAdapter()->fromSkinData($packet->skin);
|
||||||
}catch(InvalidSkinException $e){
|
}catch(InvalidSkinException $e){
|
||||||
throw PacketHandlingException::wrap($e, "Invalid skin in PlayerSkinPacket");
|
throw PacketHandlingException::wrap($e, "Invalid skin in PlayerSkinPacket");
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ use pocketmine\event\player\PlayerPreLoginEvent;
|
|||||||
use pocketmine\lang\KnownTranslationFactory;
|
use pocketmine\lang\KnownTranslationFactory;
|
||||||
use pocketmine\lang\Translatable;
|
use pocketmine\lang\Translatable;
|
||||||
use pocketmine\network\mcpe\auth\ProcessLoginTask;
|
use pocketmine\network\mcpe\auth\ProcessLoginTask;
|
||||||
use pocketmine\network\mcpe\convert\SkinAdapterSingleton;
|
|
||||||
use pocketmine\network\mcpe\JwtException;
|
use pocketmine\network\mcpe\JwtException;
|
||||||
use pocketmine\network\mcpe\JwtUtils;
|
use pocketmine\network\mcpe\JwtUtils;
|
||||||
use pocketmine\network\mcpe\NetworkSession;
|
use pocketmine\network\mcpe\NetworkSession;
|
||||||
@ -72,7 +71,7 @@ class LoginPacketHandler extends PacketHandler{
|
|||||||
$clientData = $this->parseClientData($packet->clientDataJwt);
|
$clientData = $this->parseClientData($packet->clientDataJwt);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$skin = SkinAdapterSingleton::get()->fromSkinData(ClientDataToSkinDataHelper::fromClientData($clientData));
|
$skin = $this->session->getTypeConverter()->getSkinAdapter()->fromSkinData(ClientDataToSkinDataHelper::fromClientData($clientData));
|
||||||
}catch(\InvalidArgumentException | InvalidSkinException $e){
|
}catch(\InvalidArgumentException | InvalidSkinException $e){
|
||||||
$this->session->getLogger()->debug("Invalid skin: " . $e->getMessage());
|
$this->session->getLogger()->debug("Invalid skin: " . $e->getMessage());
|
||||||
$this->session->disconnectWithError(KnownTranslationFactory::disconnectionScreen_invalidSkin());
|
$this->session->disconnectWithError(KnownTranslationFactory::disconnectionScreen_invalidSkin());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user