mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Filesystem: added fileGetContents to reduce ErrorToExceptionHandler boilerplate code
This commit is contained in:
@ -39,7 +39,6 @@ use pocketmine\world\generator\GeneratorManager;
|
||||
use pocketmine\world\World;
|
||||
use pocketmine\world\WorldCreationOptions;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
use function file_get_contents;
|
||||
use function file_put_contents;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
@ -111,9 +110,10 @@ class BedrockWorldData extends BaseNbtWorldData{
|
||||
}
|
||||
|
||||
protected function load() : CompoundTag{
|
||||
$rawLevelData = @file_get_contents($this->dataPath);
|
||||
if($rawLevelData === false){
|
||||
throw new CorruptedWorldException("Failed to read level.dat (permission denied or doesn't exist)");
|
||||
try{
|
||||
$rawLevelData = Filesystem::fileGetContents($this->dataPath);
|
||||
}catch(\RuntimeException $e){
|
||||
throw new CorruptedWorldException($e->getMessage(), 0, $e);
|
||||
}
|
||||
if(strlen($rawLevelData) <= 8){
|
||||
throw new CorruptedWorldException("Truncated level.dat");
|
||||
|
@ -37,7 +37,6 @@ use pocketmine\world\World;
|
||||
use pocketmine\world\WorldCreationOptions;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
use function ceil;
|
||||
use function file_get_contents;
|
||||
use function file_put_contents;
|
||||
use function microtime;
|
||||
use function zlib_decode;
|
||||
@ -75,9 +74,10 @@ class JavaWorldData extends BaseNbtWorldData{
|
||||
}
|
||||
|
||||
protected function load() : CompoundTag{
|
||||
$rawLevelData = @file_get_contents($this->dataPath);
|
||||
if($rawLevelData === false){
|
||||
throw new CorruptedWorldException("Failed to read level.dat (permission denied or doesn't exist)");
|
||||
try{
|
||||
$rawLevelData = Filesystem::fileGetContents($this->dataPath);
|
||||
}catch(\RuntimeException $e){
|
||||
throw new CorruptedWorldException($e->getMessage(), 0, $e);
|
||||
}
|
||||
$nbt = new BigEndianNbtSerializer();
|
||||
$decompressed = @zlib_decode($rawLevelData);
|
||||
|
Reference in New Issue
Block a user