From 3dc75644d9546e7e57439d8e07677b1c7ce66ec0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 31 Oct 2021 14:02:25 +0000 Subject: [PATCH] World: avoid duplicated logger code in initChunk() --- src/world/World.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/world/World.php b/src/world/World.php index c9fb8f816..ab7e18ce9 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2442,6 +2442,7 @@ class World implements ChunkManager{ } private function initChunk(int $chunkX, int $chunkZ, ChunkData $chunkData) : void{ + $logger = new \PrefixedLogger($this->logger, "Loading chunk $chunkX $chunkZ"); if(count($chunkData->getEntityNBT()) !== 0){ $this->timings->syncChunkLoadEntities->startTiming(); $entityFactory = EntityFactory::getInstance(); @@ -2449,8 +2450,8 @@ class World implements ChunkManager{ try{ $entity = $entityFactory->createFromData($this, $nbt); }catch(NbtDataException $e){ - $this->getLogger()->error("Chunk $chunkX $chunkZ: Bad entity data at list position $k: " . $e->getMessage()); - $this->getLogger()->logException($e); + $logger->error("Bad entity data at list position $k: " . $e->getMessage()); + $logger->logException($e); continue; } if($entity === null){ @@ -2461,7 +2462,7 @@ class World implements ChunkManager{ }elseif($saveIdTag instanceof IntTag){ //legacy MCPE format $saveId = "legacy(" . $saveIdTag->getValue() . ")"; } - $this->getLogger()->warning("Chunk $chunkX $chunkZ: Deleted unknown entity type $saveId"); + $logger->warning("Deleted unknown entity type $saveId"); } //TODO: we can't prevent entities getting added to unloaded chunks if they were saved in the wrong place //here, because entities currently add themselves to the world @@ -2477,16 +2478,16 @@ class World implements ChunkManager{ try{ $tile = $tileFactory->createFromData($this, $nbt); }catch(NbtDataException $e){ - $this->getLogger()->error("Chunk $chunkX $chunkZ: Bad tile entity data at list position $k: " . $e->getMessage()); - $this->getLogger()->logException($e); + $logger->error("Bad tile entity data at list position $k: " . $e->getMessage()); + $logger->logException($e); continue; } if($tile === null){ - $this->getLogger()->warning("Chunk $chunkX $chunkZ: Deleted unknown tile entity type " . $nbt->getString("id", "")); + $logger->warning("Deleted unknown tile entity type " . $nbt->getString("id", "")); }elseif(!$this->isChunkLoaded($tile->getPosition()->getFloorX() >> Chunk::COORD_BIT_SIZE, $tile->getPosition()->getFloorZ() >> Chunk::COORD_BIT_SIZE)){ - $this->logger->error("Chunk $chunkX $chunkZ: Found tile saved on wrong chunk - unable to fix due to correct chunk not loaded"); + $logger->error("Found tile saved on wrong chunk - unable to fix due to correct chunk not loaded"); }elseif($this->getTile($tilePosition = $tile->getPosition()) !== null){ - $this->logger->error("Chunk $chunkX $chunkZ: Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Another tile is already at that position"); + $logger->error("Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Another tile is already at that position"); }else{ $this->addTile($tile); }