Apply typehints to level\format\io namespace

This commit is contained in:
Dylan K. Taylor 2018-10-04 19:59:26 +01:00
parent b214601a82
commit b407eba1a3
6 changed files with 24 additions and 24 deletions

View File

@ -63,7 +63,7 @@ interface LevelProvider{
* @param string $generator
* @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).
@ -88,7 +88,7 @@ interface LevelProvider{
/**
* 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
@ -100,7 +100,7 @@ interface LevelProvider{
/**
* 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.

View File

@ -45,7 +45,7 @@ class BedrockLevelData extends BaseNbtLevelData{
public const GENERATOR_INFINITE = 1;
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){
case Flat::class:
$generatorType = self::GENERATOR_FLAT;

View File

@ -35,7 +35,7 @@ use pocketmine\nbt\tag\StringTag;
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
$levelData = new CompoundTag("Data", [
new ByteTag("hardcore", ($options["hardcore"] ?? false) === true ? 1 : 0),

View File

@ -68,7 +68,7 @@ class LevelDB extends BaseLevelProvider{
/** @var \LevelDB */
protected $db;
private static function checkForLevelDBExtension(){
private static function checkForLevelDBExtension() : void{
if(!extension_loaded('leveldb')){
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/");
}
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();
if(!file_exists($path . "/db")){
@ -323,7 +323,7 @@ class LevelDB extends BaseLevelProvider{
* @param CompoundTag[] $targets
* @param string $index
*/
private function writeTags(array $targets, string $index){
private function writeTags(array $targets, string $index) : void{
if(!empty($targets)){
$nbt = new LittleEndianNBTStream();
$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;
}
public function doGarbageCollection(){
public function doGarbageCollection() : void{
}
public function close(){
public function close() : void{
$this->db->close();
}

View File

@ -57,7 +57,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
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)){
mkdir($path, 0777, true);
}
@ -76,7 +76,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
return new JavaLevelData($this->getPath() . "level.dat");
}
public function doGarbageCollection(){
public function doGarbageCollection() : void{
$limit = time() - 300;
foreach($this->regions as $index => $region){
if($region->lastUsed <= $limit){
@ -92,7 +92,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
* @param int &$regionX
* @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;
$regionZ = $chunkZ >> 5;
}
@ -103,7 +103,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
*
* @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;
}
@ -123,7 +123,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
* @param int $regionX
* @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)])){
$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){
$region->close();
unset($this->regions[$index]);

View File

@ -53,7 +53,7 @@ class RegionLoader{
$this->filePath = $filePath;
}
public function open(){
public function open() : void{
$exists = file_exists($this->filePath);
if(!$exists){
touch($this->filePath);
@ -138,7 +138,7 @@ class RegionLoader{
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();
$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);
$this->locationTable[$index][0] = 0;
$this->locationTable[$index][1] = 0;
@ -182,7 +182,7 @@ class RegionLoader{
*
* @param bool $writeHeader
*/
public function close(bool $writeHeader = true){
public function close(bool $writeHeader = true) : void{
if(is_resource($this->filePointer)){
if($writeHeader){
$this->writeLocationTable();
@ -267,7 +267,7 @@ class RegionLoader{
return $shift;
}
protected function loadLocationTable(){
protected function loadLocationTable() : void{
fseek($this->filePointer, 0);
$this->lastSector = 1;
@ -301,7 +301,7 @@ class RegionLoader{
fseek($this->filePointer, 0);
}
private function writeLocationTable(){
private function writeLocationTable() : void{
$write = [];
for($i = 0; $i < 1024; ++$i){
@ -314,14 +314,14 @@ class RegionLoader{
fwrite($this->filePointer, pack("N*", ...$write), 4096 * 2);
}
protected function writeLocationIndex($index){
protected function writeLocationIndex(int $index) : void{
fseek($this->filePointer, $index << 2);
fwrite($this->filePointer, Binary::writeInt(($this->locationTable[$index][0] << 8) | $this->locationTable[$index][1]), 4);
fseek($this->filePointer, 4096 + ($index << 2));
fwrite($this->filePointer, Binary::writeInt($this->locationTable[$index][2]), 4);
}
protected function createBlank(){
protected function createBlank() : void{
fseek($this->filePointer, 0);
ftruncate($this->filePointer, 8192); // this fills the file with the null byte
$this->lastSector = 1;