Fixed #1889 Players drop their inventory when they die

This commit is contained in:
Shoghi Cervantes 2014-08-18 14:49:53 +02:00
parent 3c231118a6
commit 34711dc346
3 changed files with 26 additions and 0 deletions

View File

@ -2178,6 +2178,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return;
}
parent::kill();
if($this->inventory !== null){
$this->inventory->clearAll();
}
$message = $this->getName() ." died";
$cause = $this->getLastDamageCause();
$ev = null;

View File

@ -80,6 +80,20 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $this->nameTag;
}
public function getDrops(){
$drops = [];
if($this->inventory instanceof PlayerInventory){
foreach($this->inventory->getContents() as $item){
$drops[] = $item;
}
foreach($this->inventory->getArmorContents() as $item){
$drops[] = $item;
}
}
return $drops;
}
public function saveNBT(){
parent::saveNBT();
$this->namedtag->Inventory = new Enum("Inventory", []);

View File

@ -259,6 +259,13 @@ class PlayerInventory extends BaseInventory{
return $armor;
}
public function clearAll(){
$limit = $this->getSize() + 4;
for($index = 0; $index < $limit; ++$index){
$this->clear($index);
}
}
/**
* @param Player|Player[] $target
*/