Fix crash when new players join due to attempting to send negative inventory slot

This commit is contained in:
Dylan K. Taylor 2017-05-29 15:24:11 +01:00
parent 57379b93ce
commit 2f306c3a38
2 changed files with 4 additions and 6 deletions

View File

@ -103,6 +103,7 @@ abstract class BaseInventory implements Inventory{
}
public function getItem($index){
assert($index >= 0, "Inventory slot should not be negative");
return isset($this->slots[$index]) ? clone $this->slots[$index] : Item::get(Item::AIR, 0, 0);
}

View File

@ -214,16 +214,13 @@ class PlayerInventory extends BaseInventory{
if(!is_array($target)){
$target->dataPacket($pk);
if($target === $this->getHolder()){
if($this->getHeldItemSlot() !== -1 and $target === $this->getHolder()){
$this->sendSlot($this->getHeldItemSlot(), $target);
}
}else{
$this->getHolder()->getLevel()->getServer()->broadcastPacket($target, $pk);
foreach($target as $player){
if($player === $this->getHolder()){
$this->sendSlot($this->getHeldItemSlot(), $player);
break;
}
if($this->getHeldItemSlot() !== -1 and in_array($this->getHolder(), $target)){
$this->sendSlot($this->getHeldItemSlot(), $this->getHolder());
}
}
}