From 6b65b68ebc575ed84f9be5f1fca2be6d8331b9af Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 5 Oct 2014 16:32:15 +0200 Subject: [PATCH] Possible fix for #1661 --- src/pocketmine/level/Level.php | 8 +------ .../level/format/generic/BaseFullChunk.php | 19 +++++++++++----- .../level/format/mcregion/McRegion.php | 22 ++----------------- src/pocketmine/tile/Chest.php | 2 +- src/pocketmine/tile/Furnace.php | 3 ++- src/pocketmine/tile/Sign.php | 2 +- src/pocketmine/tile/Tile.php | 7 +++--- 7 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index f5f6a9a6d..8173078e6 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1706,10 +1706,6 @@ class Level implements ChunkManager, Metadatable{ $entity->kill(); } - if(($chunk = $this->getChunk($entity->chunkX, $entity->chunkZ)) instanceof FullChunk){ - $chunk->removeEntity($entity); - } - unset($this->entities[$entity->getID()]); } @@ -1749,9 +1745,7 @@ class Level implements ChunkManager, Metadatable{ if($tile->getLevel() !== $this){ throw new \RuntimeException("Invalid Tile level"); } - if($this->isChunkLoaded($tile->chunk->getX(), $tile->chunk->getZ())){ - $this->getChunk($tile->chunk->getX(), $tile->chunk->getZ(), true)->removeTile($tile); - } + unset($this->tiles[$tile->getID()]); } diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index 646baf1ef..8d8698355 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -267,17 +267,24 @@ abstract class BaseFullChunk implements FullChunk{ if($save === true){ $level->saveChunk($this->getX(), $this->getZ()); } - if($this->getProvider()->unloadChunk($this->getX(), $this->getZ(), $safe)){ + if($safe === true){ foreach($this->getEntities() as $entity){ if($entity instanceof Player){ - continue; + return false; } - $entity->close(); - } - foreach($this->getTiles() as $tile){ - $tile->close(); } } + + foreach($this->getEntities() as $entity){ + if($entity instanceof Player){ + continue; + } + $entity->close(); + } + foreach($this->getTiles() as $tile){ + $tile->close(); + } + return true; } public function getBlockIdArray(){ diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index 3a395c32a..350ff74d4 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -183,6 +183,7 @@ class McRegion extends BaseLevelProvider{ if($chunk instanceof FullChunk){ $this->chunks[$index] = $chunk; + return true; }else{ return false; } @@ -190,26 +191,7 @@ class McRegion extends BaseLevelProvider{ public function unloadChunk($x, $z, $safe = true){ $chunk = $this->getChunk($x, $z, false); - if($chunk instanceof FullChunk){ - if($safe === true){ - foreach($chunk->getEntities() as $entity){ - if($entity instanceof Player){ - return false; - } - } - } - - foreach($chunk->getEntities() as $entity){ - if($entity instanceof Player){ - continue; - } - $entity->close(); - } - - foreach($chunk->getTiles() as $tile){ - $tile->close(); - } - + if($chunk instanceof FullChunk and $chunk->unload(false, $safe)){ $this->chunks[$index = Level::chunkHash($x, $z)] = null; unset($this->chunks[$index]); diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index ffbabb39c..628228980 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -43,7 +43,7 @@ class Chest extends Spawnable implements InventoryHolder, Container{ protected $doubleInventory = null; public function __construct(FullChunk $chunk, Compound $nbt){ - $nbt["id"] = Tile::CHEST; + $nbt->id = new String("id", Tile::CHEST); parent::__construct($chunk, $nbt); $this->inventory = new ChestInventory($this); diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 147d759b6..f16ea7d62 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -32,6 +32,7 @@ use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Short; +use pocketmine\nbt\tag\String; use pocketmine\network\protocol\ContainerSetDataPacket; class Furnace extends Tile implements InventoryHolder, Container{ @@ -39,7 +40,7 @@ class Furnace extends Tile implements InventoryHolder, Container{ protected $inventory; public function __construct(FullChunk $chunk, Compound $nbt){ - $nbt["id"] = Tile::FURNACE; + $nbt->id = new String("id", Tile::FURNACE); parent::__construct($chunk, $nbt); $this->inventory = new FurnaceInventory($this); diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index 0d3df9e37..ce020f900 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -29,7 +29,7 @@ use pocketmine\nbt\tag\String; class Sign extends Spawnable{ public function __construct(FullChunk $chunk, Compound $nbt){ - $nbt["id"] = Tile::SIGN; + $nbt->id = new String("id", Tile::SIGN); if(!isset($nbt->Text1)){ $nbt->Text1 = new String("Text1", ""); } diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 0f70dae26..9589e1c18 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -31,6 +31,7 @@ use pocketmine\level\format\FullChunk; use pocketmine\level\Level; use pocketmine\level\Position; use pocketmine\nbt\tag\Compound; +use pocketmine\nbt\tag\Int; abstract class Tile extends Position{ const SIGN = "Sign"; @@ -88,9 +89,9 @@ abstract class Tile extends Position{ } public function saveNBT(){ - $this->namedtag["x"] = $this->x; - $this->namedtag["y"] = $this->y; - $this->namedtag["z"] = $this->z; + $this->namedtag->x = new Int("x", $this->x); + $this->namedtag->y = new Int("y", $this->y); + $this->namedtag->z = new Int("z", $this->z); } public function onUpdate(){