UpdateBlockPacket fixed and changed skinName to skinId

This commit is contained in:
Intyre 2016-06-22 01:07:09 +02:00
parent df8e1e8702
commit 6fb41c5c7f
No known key found for this signature in database
GPG Key ID: B06D41D26935005A
6 changed files with 57 additions and 36 deletions

View File

@ -567,14 +567,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
public function setDisplayName($name){
$this->displayName = $name;
if($this->spawned){
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->getSkinName(), $this->getSkinData());
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->getSkinId(), $this->getSkinData());
}
}
public function setSkin($str, $skinName){
parent::setSkin($str, $skinName);
public function setSkin($str, $skinId){
parent::setSkin($str, $skinId);
if($this->spawned){
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $skinName, $str);
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $skinId, $str);
}
}
@ -1850,7 +1850,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
break;
}
$this->setSkin($packet->skin, $packet->skinID);
$this->setSkin($packet->skin, $packet->skinId);
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if($ev->isCancelled()){

View File

@ -2180,7 +2180,7 @@ class Server{
public function addOnlinePlayer(Player $player){
$this->playerList[$player->getRawUniqueId()] = $player;
$this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinName(), $player->getSkinData());
$this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinId(), $player->getSkinData());
}
public function removeOnlinePlayer(Player $player){
@ -2194,10 +2194,10 @@ class Server{
}
}
public function updatePlayerListData(UUID $uuid, $entityId, $name, $skinName, $skinData, array $players = null){
public function updatePlayerListData(UUID $uuid, $entityId, $name, $skinId, $skinData, array $players = null){
$pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_ADD;
$pk->entries[] = [$uuid, $entityId, $name, $skinName, $skinData];
$pk->entries[] = [$uuid, $entityId, $name, $skinId, $skinData];
Server::broadcastPacket($players === null ? $this->playerList : $players, $pk);
}
@ -2212,7 +2212,7 @@ class Server{
$pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_ADD;
foreach($this->playerList as $player){
$pk->entries[] = [$player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinName(), $player->getSkinData()];
$pk->entries[] = [$player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinId(), $player->getSkinData()];
}
$p->dataPacket($pk);

View File

@ -60,7 +60,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public $height = 1.8;
public $eyeHeight = 1.62;
protected $skinName;
protected $skinId;
protected $skin;
protected $foodTickTimer = 0;
@ -72,8 +72,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $this->skin;
}
public function getSkinName(){
return $this->skinName;
public function getSkinId(){
return $this->skinId;
}
/**
@ -92,11 +92,11 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
/**
* @param string $str
* @param string $skinName
* @param string $skinId
*/
public function setSkin($str, $skinName){
public function setSkin($str, $skinId){
$this->skin = $str;
$this->skinName = $skinName;
$this->skinId = $skinId;
}
public function getFood() : float{
@ -443,7 +443,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if(strlen($this->getSkinData()) > 0){
$this->namedtag->Skin = new CompoundTag("Skin", [
"Data" => new StringTag("Data", $this->getSkinData()),
"Name" => new StringTag("Name", $this->getSkinName())
"Name" => new StringTag("Name", $this->getSkinId())
]);
}
}
@ -457,7 +457,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
}
if(!($this instanceof Player)){
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $this->skinName, $this->skin, [$player]);
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $this->skinId, $this->skin, [$player]);
}
$pk = new AddPlayerPacket();

View File

@ -796,11 +796,10 @@ class Level implements ChunkManager, Metadatable{
* @param bool $optimizeRebuilds
*/
public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, bool $optimizeRebuilds = false){
$pk = new UpdateBlockPacket();
if($optimizeRebuilds){
$chunks = [];
foreach($blocks as $b){
$pk = new UpdateBlockPacket();
if($b === null){
continue;
}
@ -812,28 +811,48 @@ class Level implements ChunkManager, Metadatable{
}
if($b instanceof Block){
$pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $first ? $flags : UpdateBlockPacket::FLAG_NONE];
$pk->x = $b->x;
$pk->z = $b->z;
$pk->y = $b->y;
$pk->blockId = $b->getId();
$pk->blockData = $b->getDamage();
$pk->flags = $first ? $flags : UpdateBlockPacket::FLAG_NONE;
}else{
$fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
$pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $first ? $flags : UpdateBlockPacket::FLAG_NONE];
$pk->x = $b->x;
$pk->z = $b->z;
$pk->y = $b->y;
$pk->blockId = $fullBlock >> 4;
$pk->blockData = $fullBlock & 0xf;
$pk->flags = $first ? $flags : UpdateBlockPacket::FLAG_NONE;
}
Server::broadcastPacket($target, $pk);
}
}else{
foreach($blocks as $b){
$pk = new UpdateBlockPacket();
if($b === null){
continue;
}
if($b instanceof Block){
$pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $flags];
$pk->x = $b->x;
$pk->z = $b->z;
$pk->y = $b->y;
$pk->blockId = $b->getId();
$pk->blockData = $b->getDamage();
$pk->flags = $flags;
}else{
$fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
$pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $flags];
$pk->x = $b->x;
$pk->z = $b->z;
$pk->y = $b->y;
$pk->blockId = $fullBlock >> 4;
$pk->blockData = $fullBlock & 0xf;
$pk->flags = $flags;
}
Server::broadcastPacket($target, $pk);
}
}
Server::broadcastPacket($target, $pk);
}
public function clearCache(bool $full = false){

View File

@ -35,7 +35,7 @@ class LoginPacket extends DataPacket{
public $identityPublicKey;
public $serverAddress;
public $skinID;
public $skinId;
public $skin = null;
public function decode(){

View File

@ -36,7 +36,12 @@ class UpdateBlockPacket extends DataPacket{
const FLAG_ALL = (self::FLAG_NEIGHBORS | self::FLAG_NETWORK);
const FLAG_ALL_PRIORITY = (self::FLAG_ALL | self::FLAG_PRIORITY);
public $records = []; //x, z, y, blockId, blockData, flags
public $x;
public $z;
public $y;
public $blockId;
public $blockData;
public $flags;
public function decode(){
@ -44,14 +49,11 @@ class UpdateBlockPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putInt(count($this->records));
foreach($this->records as $r){
$this->putInt($r[0]);
$this->putInt($r[1]);
$this->putByte($r[2]);
$this->putByte($r[3]);
$this->putByte(($r[5] << 4) | $r[4]);
}
$this->putInt($this->x);
$this->putInt($this->z);
$this->putByte($this->y);
$this->putByte($this->blockId);
$this->putByte(($this->flags << 4) | $this->blockData);
}
}