mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-10 05:34:54 +00:00
64 lines
2.1 KiB
PHP
64 lines
2.1 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/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\network\mcpe\cache;
|
|
|
|
use pocketmine\network\mcpe\protocol\AvailableActorIdentifiersPacket;
|
|
use pocketmine\network\mcpe\protocol\BiomeDefinitionListPacket;
|
|
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
|
|
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
|
|
use pocketmine\utils\Filesystem;
|
|
use pocketmine\utils\SingletonTrait;
|
|
use Symfony\Component\Filesystem\Path;
|
|
|
|
class StaticPacketCache{
|
|
use SingletonTrait;
|
|
|
|
/**
|
|
* @phpstan-return CacheableNbt<\pocketmine\nbt\tag\CompoundTag>
|
|
*/
|
|
private static function loadCompoundFromFile(string $filePath) : CacheableNbt{
|
|
return new CacheableNbt((new NetworkNbtSerializer())->read(Filesystem::fileGetContents($filePath))->mustGetCompoundTag());
|
|
}
|
|
|
|
private static function make() : self{
|
|
return new self(
|
|
BiomeDefinitionListPacket::create(self::loadCompoundFromFile(Path::join(\pocketmine\BEDROCK_DATA_PATH, 'biome_definitions.nbt'))),
|
|
AvailableActorIdentifiersPacket::create(self::loadCompoundFromFile(Path::join(\pocketmine\BEDROCK_DATA_PATH, 'entity_identifiers.nbt')))
|
|
);
|
|
}
|
|
|
|
public function __construct(
|
|
private BiomeDefinitionListPacket $biomeDefs,
|
|
private AvailableActorIdentifiersPacket $availableActorIdentifiers
|
|
){}
|
|
|
|
public function getBiomeDefs() : BiomeDefinitionListPacket{
|
|
return $this->biomeDefs;
|
|
}
|
|
|
|
public function getAvailableActorIdentifiers() : AvailableActorIdentifiersPacket{
|
|
return $this->availableActorIdentifiers;
|
|
}
|
|
}
|