mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-12 12:55:21 +00:00
Replaced some instanceof to null checks
This commit is contained in:
parent
306f492fc0
commit
a4735eaf76
@ -167,8 +167,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
protected $iusername;
|
protected $iusername;
|
||||||
protected $displayName;
|
protected $displayName;
|
||||||
protected $startAction = false;
|
protected $startAction = false;
|
||||||
/** @var Vector3|bool */
|
/** @var Vector3 */
|
||||||
protected $sleeping = false;
|
protected $sleeping = null;
|
||||||
protected $clientID = null;
|
protected $clientID = null;
|
||||||
|
|
||||||
protected $stepHeight = 0.6;
|
protected $stepHeight = 0.6;
|
||||||
@ -517,7 +517,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isSleeping(){
|
public function isSleeping(){
|
||||||
return $this->sleeping instanceof Vector3;
|
return $this->sleeping !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unloadChunk($x, $z){
|
public function unloadChunk($x, $z){
|
||||||
@ -793,7 +793,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
public function sleepOn(Vector3 $pos){
|
public function sleepOn(Vector3 $pos){
|
||||||
foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){
|
foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){
|
||||||
if($p instanceof Player){
|
if($p instanceof Player){
|
||||||
if($p->sleeping instanceof Vector3){
|
if($p->sleeping !== null){
|
||||||
if($pos->distance($p->sleeping) <= 0.1){
|
if($pos->distance($p->sleeping) <= 0.1){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -862,7 +862,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
|
|
||||||
if($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE){
|
if($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE){
|
||||||
foreach($this->level->getPlayers() as $p){
|
foreach($this->level->getPlayers() as $p){
|
||||||
if($p->sleeping === false){
|
if($p->sleeping === null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2579,6 +2579,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
if($this->dead === true){
|
if($this->dead === true){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->isCreative()){
|
if($this->isCreative()){
|
||||||
if($source instanceof EntityDamageEvent){
|
if($source instanceof EntityDamageEvent){
|
||||||
$cause = $source->getCause();
|
$cause = $source->getCause();
|
||||||
|
@ -1058,7 +1058,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
|
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
|
||||||
for($v->y = $minY; $v->y <= $maxY; ++$v->y){
|
for($v->y = $minY; $v->y <= $maxY; ++$v->y){
|
||||||
$block = $this->level->getBlock($v);
|
$block = $this->level->getBlock($v);
|
||||||
if($block !== null and $block->hasEntityCollision()){
|
if($block->hasEntityCollision()){
|
||||||
$block->onEntityCollide($this);
|
$block->onEntityCollide($this);
|
||||||
if(!($this instanceof Player)){
|
if(!($this instanceof Player)){
|
||||||
$block->addVelocityToEntity($this, $vector);
|
$block->addVelocityToEntity($this, $vector);
|
||||||
@ -1098,7 +1098,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level){
|
if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){
|
||||||
if($this->switchLevel($pos->getLevel()) === false){
|
if($this->switchLevel($pos->getLevel()) === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1113,7 +1113,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
|
|
||||||
|
|
||||||
if($this->chunk === null or ($this->chunkX !== ($this->x >> 4) and $this->chunkZ !== ($this->z >> 4))){
|
if($this->chunk === null or ($this->chunkX !== ($this->x >> 4) and $this->chunkZ !== ($this->z >> 4))){
|
||||||
if($this->chunk instanceof FullChunk){
|
if($this->chunk !== null){
|
||||||
$this->chunk->removeEntity($this);
|
$this->chunk->removeEntity($this);
|
||||||
}
|
}
|
||||||
$this->level->loadChunk($this->x >> 4, $this->z >> 4);
|
$this->level->loadChunk($this->x >> 4, $this->z >> 4);
|
||||||
|
@ -107,7 +107,7 @@ class Explosion{
|
|||||||
}
|
}
|
||||||
$block = $this->level->getBlock($vBlock);
|
$block = $this->level->getBlock($vBlock);
|
||||||
|
|
||||||
if(!($block instanceof Air)){
|
if($block->getId() !== 0){
|
||||||
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
|
$blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
|
||||||
if($blastForce > 0){
|
if($blastForce > 0){
|
||||||
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
$index = ($block->x << 15) + ($block->z << 7) + $block->y;
|
||||||
@ -181,9 +181,7 @@ class Explosion{
|
|||||||
$air = Item::get(Item::AIR);
|
$air = Item::get(Item::AIR);
|
||||||
|
|
||||||
foreach($this->affectedBlocks as $block){
|
foreach($this->affectedBlocks as $block){
|
||||||
$block->setDamage($this->level->getBlockDataAt($block->x, $block->y, $block->z));
|
if($block->getId() === Block::TNT){
|
||||||
|
|
||||||
if($block instanceof TNT){
|
|
||||||
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
|
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
|
||||||
$tnt = Entity::createEntity("PrimedTNT", $this->level->getChunk($block->x >> 4, $block->z >> 4), new Compound("", [
|
$tnt = Entity::createEntity("PrimedTNT", $this->level->getChunk($block->x >> 4, $block->z >> 4), new Compound("", [
|
||||||
"Pos" => new Enum("Pos", [
|
"Pos" => new Enum("Pos", [
|
||||||
|
@ -698,11 +698,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
* @param Vector3 $pos
|
* @param Vector3 $pos
|
||||||
*/
|
*/
|
||||||
public function updateAround(Vector3 $pos){
|
public function updateAround(Vector3 $pos){
|
||||||
if($pos instanceof Block){
|
|
||||||
$block = $pos;
|
|
||||||
}else{
|
|
||||||
$block = $this->getBlock($pos);
|
$block = $this->getBlock($pos);
|
||||||
}
|
|
||||||
|
|
||||||
for($side = 0; $side <= 5; ++$side){
|
for($side = 0; $side <= 5; ++$side){
|
||||||
$this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block->getSide($side)));
|
$this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block->getSide($side)));
|
||||||
@ -746,7 +742,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
for($v->x = $minX; $v->x < $maxX; ++$v->x){
|
for($v->x = $minX; $v->x < $maxX; ++$v->x){
|
||||||
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){
|
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){
|
||||||
$block = $this->getBlock($v);
|
$block = $this->getBlock($v);
|
||||||
if(!($block instanceof Air)){
|
if($block->getId() !== 0){
|
||||||
$block->collidesWithBB($bb, $collides);
|
$block->collidesWithBB($bb, $collides);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -768,7 +764,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$bb = $this->getBlock($pos)->getBoundingBox();
|
$bb = $this->getBlock($pos)->getBoundingBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bb instanceof AxisAlignedBB and $bb->getAverageEdgeLength() >= 1;
|
return $bb !== null and $bb->getAverageEdgeLength() >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -793,7 +789,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
for($v->x = $minX; $v->x < $maxX; ++$v->x){
|
for($v->x = $minX; $v->x < $maxX; ++$v->x){
|
||||||
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){
|
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){
|
||||||
$block = $this->getBlock($v);
|
$block = $this->getBlock($v);
|
||||||
if(!($block instanceof Air)){
|
if($block->getId() !== 0){
|
||||||
$block->collidesWithBB($bb, $collides);
|
$block->collidesWithBB($bb, $collides);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -882,7 +878,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public function getFullLight(Vector3 $pos){
|
public function getFullLight(Vector3 $pos){
|
||||||
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, true);
|
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, false);
|
||||||
$level = 0;
|
$level = 0;
|
||||||
if($chunk instanceof FullChunk){
|
if($chunk instanceof FullChunk){
|
||||||
$level = $chunk->getBlockSkyLight($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f);
|
$level = $chunk->getBlockSkyLight($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f);
|
||||||
@ -1053,7 +1049,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function setBlock(Vector3 $pos, Block $block, $direct = false, $update = true){
|
public function setBlock(Vector3 $pos, Block $block, $direct = false, $update = true){
|
||||||
if($pos->y < 0 or $pos->y >= 128 or !($block instanceof Block)){
|
if($pos->y < 0 or $pos->y >= 128){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1441,7 +1437,6 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
for($x = $minX; $x <= $maxX; ++$x){
|
for($x = $minX; $x <= $maxX; ++$x){
|
||||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||||
if($this->isChunkLoaded($x, $z)){
|
|
||||||
foreach($this->getChunkEntities($x, $z) as $ent){
|
foreach($this->getChunkEntities($x, $z) as $ent){
|
||||||
if($ent !== $entity and $ent->boundingBox->intersectsWith($bb)){
|
if($ent !== $entity and $ent->boundingBox->intersectsWith($bb)){
|
||||||
$nearby[] = $ent;
|
$nearby[] = $ent;
|
||||||
@ -1449,7 +1444,6 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $nearby;
|
return $nearby;
|
||||||
}
|
}
|
||||||
@ -1489,12 +1483,9 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
* @return Tile
|
* @return Tile
|
||||||
*/
|
*/
|
||||||
public function getTile(Vector3 $pos){
|
public function getTile(Vector3 $pos){
|
||||||
if($pos instanceof Position and $pos->getLevel() !== $this){
|
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, false);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4);
|
|
||||||
|
|
||||||
if($chunk instanceof FullChunk){
|
if($chunk !== null){
|
||||||
return $chunk->getTile($pos->x & 0x0f, $pos->y & 0xff, $pos->z & 0x0f);
|
return $chunk->getTile($pos->x & 0x0f, $pos->y & 0xff, $pos->z & 0x0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1510,7 +1501,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
* @return Entity[]
|
* @return Entity[]
|
||||||
*/
|
*/
|
||||||
public function getChunkEntities($X, $Z){
|
public function getChunkEntities($X, $Z){
|
||||||
return ($chunk = $this->getChunk($X, $Z)) instanceof FullChunk ? $chunk->getEntities() : [];
|
return ($chunk = $this->getChunk($X, $Z)) !== null ? $chunk->getEntities() : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1522,7 +1513,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
* @return Tile[]
|
* @return Tile[]
|
||||||
*/
|
*/
|
||||||
public function getChunkTiles($X, $Z){
|
public function getChunkTiles($X, $Z){
|
||||||
return ($chunk = $this->getChunk($X, $Z)) instanceof FullChunk ? $chunk->getTiles() : [];
|
return ($chunk = $this->getChunk($X, $Z)) !== null ? $chunk->getTiles() : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1698,7 +1689,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
public function getChunk($x, $z, $create = false){
|
public function getChunk($x, $z, $create = false){
|
||||||
if(isset($this->chunks[$index = Level::chunkHash($x, $z)])){
|
if(isset($this->chunks[$index = Level::chunkHash($x, $z)])){
|
||||||
return $this->chunks[$index];
|
return $this->chunks[$index];
|
||||||
}elseif($this->loadChunk($x, $z, $create) and $this->chunks[$index] instanceof FullChunk){
|
}elseif($this->loadChunk($x, $z, $create) and $this->chunks[$index] !== null){
|
||||||
return $this->chunks[$index];
|
return $this->chunks[$index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1719,11 +1710,11 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function generateChunkCallback($x, $z, FullChunk $chunk){
|
public function generateChunkCallback($x, $z, FullChunk $chunk){
|
||||||
$oldChunk = $this->getChunk($x, $z);
|
$oldChunk = $this->getChunk($x, $z, false);
|
||||||
unset($this->chunkGenerationQueue[Level::chunkHash($x, $z)]);
|
unset($this->chunkGenerationQueue[Level::chunkHash($x, $z)]);
|
||||||
$this->setChunk($x, $z, $chunk);
|
$this->setChunk($x, $z, $chunk);
|
||||||
$chunk = $this->getChunk($x, $z);
|
$chunk = $this->getChunk($x, $z, false);
|
||||||
if($chunk instanceof FullChunk and (!($oldChunk instanceof FullChunk) or $oldChunk->isPopulated() === false) and $chunk->isPopulated()){
|
if($chunk !== null and (!($oldChunk !== null) or $oldChunk->isPopulated() === false) and $chunk->isPopulated()){
|
||||||
$this->server->getPluginManager()->callEvent(new ChunkPopulateEvent($chunk));
|
$this->server->getPluginManager()->callEvent(new ChunkPopulateEvent($chunk));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1755,10 +1746,6 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
* @return int 0-127
|
* @return int 0-127
|
||||||
*/
|
*/
|
||||||
public function getHighestBlockAt($x, $z){
|
public function getHighestBlockAt($x, $z){
|
||||||
if(!$this->isChunkLoaded($x >> 4, $z >> 4)){
|
|
||||||
$this->loadChunk($x >> 4, $z >> 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getChunk($x >> 4, $z >> 4, true)->getHighestBlockAt($x & 0x0f, $z & 0x0f);
|
return $this->getChunk($x >> 4, $z >> 4, true)->getHighestBlockAt($x & 0x0f, $z & 0x0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1780,7 +1767,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
*/
|
*/
|
||||||
public function isChunkGenerated($x, $z){
|
public function isChunkGenerated($x, $z){
|
||||||
$chunk = $this->getChunk($x, $z);
|
$chunk = $this->getChunk($x, $z);
|
||||||
return $chunk instanceof FullChunk ? $chunk->isGenerated() : false;
|
return $chunk !== null ? $chunk->isGenerated() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1791,7 +1778,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
*/
|
*/
|
||||||
public function isChunkPopulated($x, $z){
|
public function isChunkPopulated($x, $z){
|
||||||
$chunk = $this->getChunk($x, $z);
|
$chunk = $this->getChunk($x, $z);
|
||||||
return $chunk instanceof FullChunk ? $chunk->isPopulated() : false;
|
return $chunk !== null ? $chunk->isPopulated() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1964,7 +1951,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->cancelUnloadChunkRequest($x, $z);
|
$this->cancelUnloadChunkRequest($x, $z);
|
||||||
|
|
||||||
$chunk = $this->provider->getChunk($x, $z, $generate);
|
$chunk = $this->provider->getChunk($x, $z, $generate);
|
||||||
if($chunk instanceof FullChunk){
|
if($chunk !== null){
|
||||||
$this->chunks[$index] = $chunk;
|
$this->chunks[$index] = $chunk;
|
||||||
$chunk->initChunk();
|
$chunk->initChunk();
|
||||||
}else{
|
}else{
|
||||||
@ -1972,7 +1959,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->provider->loadChunk($x, $z, $generate);
|
$this->provider->loadChunk($x, $z, $generate);
|
||||||
$this->timings->syncChunkLoadTimer->stopTiming();
|
$this->timings->syncChunkLoadTimer->stopTiming();
|
||||||
|
|
||||||
if(($chunk = $this->provider->getChunk($x, $z)) instanceof FullChunk){
|
if(($chunk = $this->provider->getChunk($x, $z)) !== null){
|
||||||
$this->chunks[$index] = $chunk;
|
$this->chunks[$index] = $chunk;
|
||||||
$chunk->initChunk();
|
$chunk->initChunk();
|
||||||
}else{
|
}else{
|
||||||
@ -2014,7 +2001,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
$chunk = $this->getChunk($x, $z);
|
$chunk = $this->getChunk($x, $z);
|
||||||
|
|
||||||
if($chunk instanceof FullChunk){
|
if($chunk !== null){
|
||||||
$this->server->getPluginManager()->callEvent($ev = new ChunkUnloadEvent($chunk));
|
$this->server->getPluginManager()->callEvent($ev = new ChunkUnloadEvent($chunk));
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
return false;
|
return false;
|
||||||
@ -2022,7 +2009,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if($chunk instanceof FullChunk and $chunk->hasChanged() and $this->getAutoSave()){
|
if($chunk !== null and $chunk->hasChanged() and $this->getAutoSave()){
|
||||||
$this->provider->setChunk($x, $z, $chunk);
|
$this->provider->setChunk($x, $z, $chunk);
|
||||||
$this->provider->saveChunk($x, $z);
|
$this->provider->saveChunk($x, $z);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ class Position extends Vector3{
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isValid(){
|
public function isValid(){
|
||||||
return isset($this->level) and $this->level instanceof Level;
|
return $this->level !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,21 +109,6 @@ class Position extends Vector3{
|
|||||||
return Position::fromObject(parent::getSide($side, $step), $this->level);
|
return Position::fromObject(parent::getSide($side, $step), $this->level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the distance between two points or objects
|
|
||||||
*
|
|
||||||
* @param Vector3 $pos
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public function distance(Vector3 $pos){
|
|
||||||
if(($pos instanceof Position) and $pos->getLevel() !== $this->getLevel()){
|
|
||||||
return PHP_INT_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::distance($pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString(){
|
public function __toString(){
|
||||||
return "Position(level=" . ($this->isValid() ? $this->getLevel()->getName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
|
return "Position(level=" . ($this->isValid() ? $this->getLevel()->getName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user