mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
Apply typehints to level\format\io namespace
This commit is contained in:
parent
b214601a82
commit
b407eba1a3
@ -63,7 +63,7 @@ interface LevelProvider{
|
|||||||
* @param string $generator
|
* @param string $generator
|
||||||
* @param array[] $options
|
* @param array[] $options
|
||||||
*/
|
*/
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []);
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a chunk (usually to disk).
|
* Saves a chunk (usually to disk).
|
||||||
@ -88,7 +88,7 @@ interface LevelProvider{
|
|||||||
/**
|
/**
|
||||||
* Performs garbage collection in the level provider, such as cleaning up regions in Region-based worlds.
|
* Performs garbage collection in the level provider, such as cleaning up regions in Region-based worlds.
|
||||||
*/
|
*/
|
||||||
public function doGarbageCollection();
|
public function doGarbageCollection() : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about the world
|
* Returns information about the world
|
||||||
@ -100,7 +100,7 @@ interface LevelProvider{
|
|||||||
/**
|
/**
|
||||||
* Performs cleanups necessary when the level provider is closed and no longer needed.
|
* Performs cleanups necessary when the level provider is closed and no longer needed.
|
||||||
*/
|
*/
|
||||||
public function close();
|
public function close() : void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a generator which yields all the chunks in this level.
|
* Returns a generator which yields all the chunks in this level.
|
||||||
|
@ -45,7 +45,7 @@ class BedrockLevelData extends BaseNbtLevelData{
|
|||||||
public const GENERATOR_INFINITE = 1;
|
public const GENERATOR_INFINITE = 1;
|
||||||
public const GENERATOR_FLAT = 2;
|
public const GENERATOR_FLAT = 2;
|
||||||
|
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []){
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
||||||
switch($generator){
|
switch($generator){
|
||||||
case Flat::class:
|
case Flat::class:
|
||||||
$generatorType = self::GENERATOR_FLAT;
|
$generatorType = self::GENERATOR_FLAT;
|
||||||
|
@ -35,7 +35,7 @@ use pocketmine\nbt\tag\StringTag;
|
|||||||
|
|
||||||
class JavaLevelData extends BaseNbtLevelData{
|
class JavaLevelData extends BaseNbtLevelData{
|
||||||
|
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = [], int $version = 19133){
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = [], int $version = 19133) : void{
|
||||||
//TODO, add extra details
|
//TODO, add extra details
|
||||||
$levelData = new CompoundTag("Data", [
|
$levelData = new CompoundTag("Data", [
|
||||||
new ByteTag("hardcore", ($options["hardcore"] ?? false) === true ? 1 : 0),
|
new ByteTag("hardcore", ($options["hardcore"] ?? false) === true ? 1 : 0),
|
||||||
|
@ -68,7 +68,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
/** @var \LevelDB */
|
/** @var \LevelDB */
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
private static function checkForLevelDBExtension(){
|
private static function checkForLevelDBExtension() : void{
|
||||||
if(!extension_loaded('leveldb')){
|
if(!extension_loaded('leveldb')){
|
||||||
throw new LevelException("The leveldb PHP extension is required to use this world format");
|
throw new LevelException("The leveldb PHP extension is required to use this world format");
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
return file_exists($path . "/level.dat") and is_dir($path . "/db/");
|
return file_exists($path . "/level.dat") and is_dir($path . "/db/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []){
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
||||||
self::checkForLevelDBExtension();
|
self::checkForLevelDBExtension();
|
||||||
|
|
||||||
if(!file_exists($path . "/db")){
|
if(!file_exists($path . "/db")){
|
||||||
@ -323,7 +323,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
* @param CompoundTag[] $targets
|
* @param CompoundTag[] $targets
|
||||||
* @param string $index
|
* @param string $index
|
||||||
*/
|
*/
|
||||||
private function writeTags(array $targets, string $index){
|
private function writeTags(array $targets, string $index) : void{
|
||||||
if(!empty($targets)){
|
if(!empty($targets)){
|
||||||
$nbt = new LittleEndianNBTStream();
|
$nbt = new LittleEndianNBTStream();
|
||||||
$this->db->put($index, $nbt->write($targets));
|
$this->db->put($index, $nbt->write($targets));
|
||||||
@ -347,11 +347,11 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
return $this->db->get(LevelDB::chunkIndex($chunkX, $chunkZ) . self::TAG_VERSION) !== false;
|
return $this->db->get(LevelDB::chunkIndex($chunkX, $chunkZ) . self::TAG_VERSION) !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function doGarbageCollection(){
|
public function doGarbageCollection() : void{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(){
|
public function close() : void{
|
||||||
$this->db->close();
|
$this->db->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []){
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
||||||
if(!file_exists($path)){
|
if(!file_exists($path)){
|
||||||
mkdir($path, 0777, true);
|
mkdir($path, 0777, true);
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
return new JavaLevelData($this->getPath() . "level.dat");
|
return new JavaLevelData($this->getPath() . "level.dat");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function doGarbageCollection(){
|
public function doGarbageCollection() : void{
|
||||||
$limit = time() - 300;
|
$limit = time() - 300;
|
||||||
foreach($this->regions as $index => $region){
|
foreach($this->regions as $index => $region){
|
||||||
if($region->lastUsed <= $limit){
|
if($region->lastUsed <= $limit){
|
||||||
@ -92,7 +92,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
* @param int &$regionX
|
* @param int &$regionX
|
||||||
* @param int &$regionZ
|
* @param int &$regionZ
|
||||||
*/
|
*/
|
||||||
public static function getRegionIndex(int $chunkX, int $chunkZ, &$regionX, &$regionZ){
|
public static function getRegionIndex(int $chunkX, int $chunkZ, &$regionX, &$regionZ) : void{
|
||||||
$regionX = $chunkX >> 5;
|
$regionX = $chunkX >> 5;
|
||||||
$regionZ = $chunkZ >> 5;
|
$regionZ = $chunkZ >> 5;
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
*
|
*
|
||||||
* @return RegionLoader|null
|
* @return RegionLoader|null
|
||||||
*/
|
*/
|
||||||
protected function getRegion(int $regionX, int $regionZ){
|
protected function getRegion(int $regionX, int $regionZ) : ?RegionLoader{
|
||||||
return $this->regions[Level::chunkHash($regionX, $regionZ)] ?? null;
|
return $this->regions[Level::chunkHash($regionX, $regionZ)] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
* @param int $regionX
|
* @param int $regionX
|
||||||
* @param int $regionZ
|
* @param int $regionZ
|
||||||
*/
|
*/
|
||||||
protected function loadRegion(int $regionX, int $regionZ){
|
protected function loadRegion(int $regionX, int $regionZ) : void{
|
||||||
if(!isset($this->regions[$index = Level::chunkHash($regionX, $regionZ)])){
|
if(!isset($this->regions[$index = Level::chunkHash($regionX, $regionZ)])){
|
||||||
$path = $this->pathToRegion($regionX, $regionZ);
|
$path = $this->pathToRegion($regionX, $regionZ);
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(){
|
public function close() : void{
|
||||||
foreach($this->regions as $index => $region){
|
foreach($this->regions as $index => $region){
|
||||||
$region->close();
|
$region->close();
|
||||||
unset($this->regions[$index]);
|
unset($this->regions[$index]);
|
||||||
|
@ -53,7 +53,7 @@ class RegionLoader{
|
|||||||
$this->filePath = $filePath;
|
$this->filePath = $filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function open(){
|
public function open() : void{
|
||||||
$exists = file_exists($this->filePath);
|
$exists = file_exists($this->filePath);
|
||||||
if(!$exists){
|
if(!$exists){
|
||||||
touch($this->filePath);
|
touch($this->filePath);
|
||||||
@ -138,7 +138,7 @@ class RegionLoader{
|
|||||||
return $this->isChunkGenerated(self::getChunkOffset($x, $z));
|
return $this->isChunkGenerated(self::getChunkOffset($x, $z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function writeChunk(int $x, int $z, string $chunkData){
|
public function writeChunk(int $x, int $z, string $chunkData) : void{
|
||||||
$this->lastUsed = time();
|
$this->lastUsed = time();
|
||||||
|
|
||||||
$length = strlen($chunkData) + 1;
|
$length = strlen($chunkData) + 1;
|
||||||
@ -167,7 +167,7 @@ class RegionLoader{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeChunk(int $x, int $z){
|
public function removeChunk(int $x, int $z) : void{
|
||||||
$index = self::getChunkOffset($x, $z);
|
$index = self::getChunkOffset($x, $z);
|
||||||
$this->locationTable[$index][0] = 0;
|
$this->locationTable[$index][0] = 0;
|
||||||
$this->locationTable[$index][1] = 0;
|
$this->locationTable[$index][1] = 0;
|
||||||
@ -182,7 +182,7 @@ class RegionLoader{
|
|||||||
*
|
*
|
||||||
* @param bool $writeHeader
|
* @param bool $writeHeader
|
||||||
*/
|
*/
|
||||||
public function close(bool $writeHeader = true){
|
public function close(bool $writeHeader = true) : void{
|
||||||
if(is_resource($this->filePointer)){
|
if(is_resource($this->filePointer)){
|
||||||
if($writeHeader){
|
if($writeHeader){
|
||||||
$this->writeLocationTable();
|
$this->writeLocationTable();
|
||||||
@ -267,7 +267,7 @@ class RegionLoader{
|
|||||||
return $shift;
|
return $shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadLocationTable(){
|
protected function loadLocationTable() : void{
|
||||||
fseek($this->filePointer, 0);
|
fseek($this->filePointer, 0);
|
||||||
$this->lastSector = 1;
|
$this->lastSector = 1;
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ class RegionLoader{
|
|||||||
fseek($this->filePointer, 0);
|
fseek($this->filePointer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function writeLocationTable(){
|
private function writeLocationTable() : void{
|
||||||
$write = [];
|
$write = [];
|
||||||
|
|
||||||
for($i = 0; $i < 1024; ++$i){
|
for($i = 0; $i < 1024; ++$i){
|
||||||
@ -314,14 +314,14 @@ class RegionLoader{
|
|||||||
fwrite($this->filePointer, pack("N*", ...$write), 4096 * 2);
|
fwrite($this->filePointer, pack("N*", ...$write), 4096 * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function writeLocationIndex($index){
|
protected function writeLocationIndex(int $index) : void{
|
||||||
fseek($this->filePointer, $index << 2);
|
fseek($this->filePointer, $index << 2);
|
||||||
fwrite($this->filePointer, Binary::writeInt(($this->locationTable[$index][0] << 8) | $this->locationTable[$index][1]), 4);
|
fwrite($this->filePointer, Binary::writeInt(($this->locationTable[$index][0] << 8) | $this->locationTable[$index][1]), 4);
|
||||||
fseek($this->filePointer, 4096 + ($index << 2));
|
fseek($this->filePointer, 4096 + ($index << 2));
|
||||||
fwrite($this->filePointer, Binary::writeInt($this->locationTable[$index][2]), 4);
|
fwrite($this->filePointer, Binary::writeInt($this->locationTable[$index][2]), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createBlank(){
|
protected function createBlank() : void{
|
||||||
fseek($this->filePointer, 0);
|
fseek($this->filePointer, 0);
|
||||||
ftruncate($this->filePointer, 8192); // this fills the file with the null byte
|
ftruncate($this->filePointer, 8192); // this fills the file with the null byte
|
||||||
$this->lastSector = 1;
|
$this->lastSector = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user