PocketMine-MP/src/pocketmine/network/protocol/ResourcePackStackPacket.php
2017-03-08 20:28:20 +00:00

78 lines
2.2 KiB
PHP

<?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/
*
*
*/
namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\network\PocketEditionNetworkSession;
use pocketmine\resourcepacks\ResourcePackInfoEntry;
class ResourcePackStackPacket extends DataPacket{
const NETWORK_ID = Info::RESOURCE_PACK_STACK_PACKET;
public $mustAccept = false;
/** @var ResourcePackInfoEntry[] */
public $behaviorPackStack = [];
/** @var ResourcePackInfoEntry[] */
public $resourcePackStack = [];
public function decode(){
$this->mustAccept = $this->getBool();
$behaviorPackCount = $this->getLShort();
while($behaviorPackCountCount-- > 0){
$packId = $this->getString();
$version = $this->getString();
$this->behaviorPackStack[] = new ResourcePackInfoEntry($packId, $version);
}
$resourcePackCount = $this->getLShort();
while($resourcePackCount-- > 0){
$packId = $this->getString();
$version = $this->getString();
$this->resourcePackStack[] = new ResourcePackInfoEntry($packId, $version);
}
}
public function encode(){
$this->reset();
$this->putBool($this->mustAccept);
$this->putLShort(count($this->behaviorPackStack));
foreach($this->behaviorPackStack as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getVersion());
}
$this->putLShort(count($this->resourcePackStack));
foreach($this->resourcePackStack as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getVersion());
}
}
public function handle(PocketEditionNetworkSession $session) : bool{
return $session->handleResourcePackStack($this);
}
}