Last active
April 18, 2017 23:42
-
-
Save SOF3/cff6aaa6dbbd3784c86fc9a77e747c7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ReadOnlyFileStreamWrapper{ | |
const SCHEME_RAW = "pmmpreadonly"; | |
const SCHEME = self::SCHEME_RAW . "://"; | |
private $realPointer; | |
public function stream_open($path, $mode){ | |
assert(substr($path, 0, strlen(self::SCHEME)) === self::SCHEME); | |
$this->realPointer = fopen(substr($path, strlen(self::SCHEME)), $mode); | |
stream_set_read_buffer($this->realPointer, 1024 * 16); //16KB | |
} | |
public function stream_read($count){ | |
return fread($this->realPointer, $count); | |
} | |
public function stream_close(){ | |
fclose($this->realPointer); | |
} | |
public function stream_seek($offset, $whence = SEEK_SET){ | |
return fseek($this->realPointer, $offset, $whence); | |
} | |
public function stream_tell(){ | |
return ftell($this->realPointer); | |
} | |
public function stream_eof(){ | |
return feof($this->realPointer); | |
} | |
public function stream_truncate($size){ | |
return ftruncate($this->realPointer, $size); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ReadOnlyMcRegion extends \pocketmine\level\format\io\region\McRegion{ | |
protected function loadRegion(int $x, int $z){ | |
if(!isset($this->regions[$index = Level::chunkHash($x, $z)])){ | |
$this->regions[$index] = new ReadOnlyRegionLoader($this, $x, $z, static::REGION_FILE_EXTENSION); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use pocketmine\level\format\io\region\{RegionLoader, McRegion}; | |
stream_wrapper_register(ReadOnlyFileStreamWrapper::SCHEME_RAW, ReadOnlyFileStreamWrapper::class); | |
class ReadOnlyRegionLoader extends RegionLoader{ | |
public function __construct(McRegion $level, int $regionX, int $regionZ, string $fileExtension = McRegion::REGION_FILE_EXTENSION){ | |
parent::__construct($level, $regionX, $regionZ, $fileExtension); | |
fclose($this->filePointer); | |
$this->filePointer = fopen(ReadOnlyFileStreamWrapper::SCHEME . $this->filePath, "rb"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment