mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 04:00:29 +00:00
Position: add getLevelNonNull()
this allows assuming that a position has a valid world in places where it's never expected to not be valid. Since this is the vast majority of usages, it eliminates a lot of possible null-pointer warnings given by static analysers. TODO: Consider whether we can make Position->getLevel/World use this behaviour out of the box in the next major version.
This commit is contained in:
@@ -74,7 +74,7 @@ class ChestInventory extends ContainerInventory{
|
||||
if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){
|
||||
//TODO: this crap really shouldn't be managed by the inventory
|
||||
$this->broadcastBlockEventPacket(true);
|
||||
$this->getHolder()->getLevel()->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound());
|
||||
$this->getHolder()->getLevelNonNull()->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class ChestInventory extends ContainerInventory{
|
||||
if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){
|
||||
//TODO: this crap really shouldn't be managed by the inventory
|
||||
$this->broadcastBlockEventPacket(false);
|
||||
$this->getHolder()->getLevel()->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound());
|
||||
$this->getHolder()->getLevelNonNull()->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound());
|
||||
}
|
||||
parent::onClose($who);
|
||||
}
|
||||
@@ -96,6 +96,6 @@ class ChestInventory extends ContainerInventory{
|
||||
$pk->z = (int) $holder->z;
|
||||
$pk->eventType = 1; //it's always 1 for a chest
|
||||
$pk->eventData = $isOpen ? 1 : 0;
|
||||
$holder->getLevel()->broadcastPacketToViewers($holder, $pk);
|
||||
$holder->getLevelNonNull()->broadcastPacketToViewers($holder, $pk);
|
||||
}
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ class EnderChestInventory extends ChestInventory{
|
||||
*/
|
||||
public function setHolderPosition(EnderChest $enderChest){
|
||||
$this->holder->setComponents($enderChest->getFloorX(), $enderChest->getFloorY(), $enderChest->getFloorZ());
|
||||
$this->holder->setLevel($enderChest->getLevel());
|
||||
$this->holder->setLevel($enderChest->getLevelNonNull());
|
||||
}
|
||||
|
||||
protected function getOpenSound() : int{
|
||||
|
@@ -173,7 +173,7 @@ class PlayerInventory extends BaseInventory{
|
||||
$this->sendSlot($this->getHeldItemIndex(), $target);
|
||||
}
|
||||
}else{
|
||||
$this->getHolder()->getLevel()->getServer()->broadcastPacket($target, $pk);
|
||||
$this->getHolder()->getLevelNonNull()->getServer()->broadcastPacket($target, $pk);
|
||||
if(in_array($this->getHolder(), $target, true)){
|
||||
$this->sendSlot($this->getHeldItemIndex(), $this->getHolder());
|
||||
}
|
||||
|
Reference in New Issue
Block a user