Added BaseInventory->removeAllViewers()

This commit is contained in:
Dylan K. Taylor 2017-10-16 11:15:03 +01:00
parent 1641183674
commit 68809d992b
4 changed files with 15 additions and 15 deletions

View File

@ -541,10 +541,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function close(){
if(!$this->closed){
if($this->inventory !== null){
foreach($this->inventory->getViewers() as $viewer){
$viewer->removeWindow($this->inventory);
}
$this->inventory->removeAllViewers(true);
$this->inventory = null;
}
parent::close();

View File

@ -349,6 +349,17 @@ abstract class BaseInventory implements Inventory{
return $this->viewers;
}
/**
* Removes the inventory window from all players currently viewing it.
* @param bool $force Force removal of permanent windows such as the player's own inventory. Used internally.
*/
public function removeAllViewers(bool $force = false) : void{
foreach($this->viewers as $hash => $viewer){
$viewer->removeWindow($this, $force);
unset($this->viewers[$hash]);
}
}
public function getHolder(){
return $this->holder;
}

View File

@ -59,15 +59,10 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
public function close(){
if($this->closed === false){
foreach($this->getInventory()->getViewers() as $player){
$player->removeWindow($this->getInventory());
}
foreach($this->getInventory()->getViewers() as $player){
$player->removeWindow($this->getRealInventory());
}
$this->inventory->removeAllViewers(true);
if($this->doubleInventory !== null){
$this->doubleInventory->removeAllViewers(true);
$this->doubleInventory->invalidate();
$this->doubleInventory = null;
}

View File

@ -97,10 +97,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
public function close(){
if($this->closed === false){
foreach($this->getInventory()->getViewers() as $player){
$player->removeWindow($this->getInventory());
}
$this->inventory->removeAllViewers(true);
$this->inventory = null;
parent::close();