Fixed a bunch of things PHPStan finds unpalatable

close #2614, fix a bunch of docs bugs, fix sendCreativeContents() crash on Human holders, move some inline variable declarations
This commit is contained in:
Dylan K. Taylor
2019-01-04 00:23:09 +00:00
parent 5e0c3333cf
commit d71a543d10
11 changed files with 62 additions and 39 deletions

View File

@ -27,6 +27,8 @@ declare(strict_types=1);
namespace pocketmine\inventory;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player;
interface Inventory{
@ -120,6 +122,15 @@ interface Inventory{
*/
public function setContents(array $items, bool $send = true) : void;
/**
* Drops the contents of the inventory into the specified Level at the specified position and clears the inventory
* contents.
*
* @param Level $level
* @param Vector3 $position
*/
public function dropContents(Level $level, Vector3 $position) : void;
/**
* @param Player|Player[] $target
*/

View File

@ -196,16 +196,21 @@ class PlayerInventory extends BaseInventory{
}
public function sendCreativeContents(){
//TODO: this mess shouldn't be in here
$holder = $this->getHolder();
if(!($holder instanceof Player)){
throw new \LogicException("Cannot send creative inventory contents to non-player inventory holder");
}
$pk = new InventoryContentPacket();
$pk->windowId = ContainerIds::CREATIVE;
if(!$this->getHolder()->isSpectator()){ //fill it for all gamemodes except spectator
if(!$holder->isSpectator()){ //fill it for all gamemodes except spectator
foreach(Item::getCreativeItems() as $i => $item){
$pk->items[$i] = clone $item;
}
}
$this->getHolder()->dataPacket($pk);
$holder->dataPacket($pk);
}
/**