mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Replace disallowed operators in src/world/
This commit is contained in:
@ -839,7 +839,7 @@ class World implements ChunkManager{
|
||||
$this->timings->scheduledBlockUpdates->startTiming();
|
||||
|
||||
//Delayed updates
|
||||
while($this->scheduledBlockUpdateQueue->count() > 0 and $this->scheduledBlockUpdateQueue->current()["priority"] <= $currentTick){
|
||||
while($this->scheduledBlockUpdateQueue->count() > 0 && $this->scheduledBlockUpdateQueue->current()["priority"] <= $currentTick){
|
||||
/** @var Vector3 $vec */
|
||||
$vec = $this->scheduledBlockUpdateQueue->extract()["data"];
|
||||
unset($this->scheduledBlockUpdateQueueIndex[World::blockHash($vec->x, $vec->y, $vec->z)]);
|
||||
@ -878,7 +878,7 @@ class World implements ChunkManager{
|
||||
//Update entities that need update
|
||||
Timings::$tickEntity->startTiming();
|
||||
foreach($this->updateEntities as $id => $entity){
|
||||
if($entity->isClosed() or $entity->isFlaggedForDespawn() or !$entity->onUpdate($currentTick)){
|
||||
if($entity->isClosed() || $entity->isFlaggedForDespawn() || !$entity->onUpdate($currentTick)){
|
||||
unset($this->updateEntities[$id]);
|
||||
}
|
||||
if($entity->isFlaggedForDespawn()){
|
||||
@ -918,7 +918,7 @@ class World implements ChunkManager{
|
||||
|
||||
}
|
||||
|
||||
if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){
|
||||
if($this->sleepTicks > 0 && --$this->sleepTicks <= 0){
|
||||
$this->checkSleep();
|
||||
}
|
||||
|
||||
@ -949,7 +949,7 @@ class World implements ChunkManager{
|
||||
if($resetTime){
|
||||
$time = $this->getTimeOfDay();
|
||||
|
||||
if($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE){
|
||||
if($time >= World::TIME_NIGHT && $time < World::TIME_SUNRISE){
|
||||
$this->setTime($this->getTime() + World::TIME_FULL - $time);
|
||||
|
||||
foreach($this->getPlayers() as $p){
|
||||
@ -1028,7 +1028,7 @@ class World implements ChunkManager{
|
||||
}
|
||||
|
||||
private function tickChunks() : void{
|
||||
if($this->chunksPerTick <= 0 or count($this->tickingLoaders) === 0){
|
||||
if($this->chunksPerTick <= 0 || count($this->tickingLoaders) === 0){
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1049,7 +1049,7 @@ class World implements ChunkManager{
|
||||
$dx = mt_rand(-$randRange, $randRange);
|
||||
$dz = mt_rand(-$randRange, $randRange);
|
||||
$hash = World::chunkHash($dx + $chunkX, $dz + $chunkZ);
|
||||
if(!isset($chunkTickList[$hash]) and isset($this->chunks[$hash]) and $this->isChunkTickable($dx + $chunkX, $dz + $chunkZ)){
|
||||
if(!isset($chunkTickList[$hash]) && isset($this->chunks[$hash]) && $this->isChunkTickable($dx + $chunkX, $dz + $chunkZ)){
|
||||
$chunkTickList[$hash] = true;
|
||||
}
|
||||
}
|
||||
@ -1164,7 +1164,7 @@ class World implements ChunkManager{
|
||||
|
||||
public function save(bool $force = false) : bool{
|
||||
|
||||
if(!$this->getAutoSave() and !$force){
|
||||
if(!$this->getAutoSave() && !$force){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1200,8 +1200,8 @@ class World implements ChunkManager{
|
||||
*/
|
||||
public function scheduleDelayedBlockUpdate(Vector3 $pos, int $delay) : void{
|
||||
if(
|
||||
!$this->isInWorld($pos->x, $pos->y, $pos->z) or
|
||||
(isset($this->scheduledBlockUpdateQueueIndex[$index = World::blockHash($pos->x, $pos->y, $pos->z)]) and $this->scheduledBlockUpdateQueueIndex[$index] <= $delay)
|
||||
!$this->isInWorld($pos->x, $pos->y, $pos->z) ||
|
||||
(isset($this->scheduledBlockUpdateQueueIndex[$index = World::blockHash($pos->x, $pos->y, $pos->z)]) && $this->scheduledBlockUpdateQueueIndex[$index] <= $delay)
|
||||
){
|
||||
return;
|
||||
}
|
||||
@ -1520,9 +1520,9 @@ class World implements ChunkManager{
|
||||
|
||||
public function isInWorld(int $x, int $y, int $z) : bool{
|
||||
return (
|
||||
$x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and
|
||||
$y < $this->maxY and $y >= $this->minY and
|
||||
$z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN
|
||||
$x <= Limits::INT32_MAX && $x >= Limits::INT32_MIN &&
|
||||
$y < $this->maxY && $y >= $this->minY &&
|
||||
$z <= Limits::INT32_MAX && $z >= Limits::INT32_MIN
|
||||
);
|
||||
}
|
||||
|
||||
@ -1556,7 +1556,7 @@ class World implements ChunkManager{
|
||||
if($this->isInWorld($x, $y, $z)){
|
||||
$relativeBlockHash = World::chunkBlockHash($x, $y, $z);
|
||||
|
||||
if($cached and isset($this->blockCache[$chunkHash][$relativeBlockHash])){
|
||||
if($cached && isset($this->blockCache[$chunkHash][$relativeBlockHash])){
|
||||
return $this->blockCache[$chunkHash][$relativeBlockHash];
|
||||
}
|
||||
|
||||
@ -1586,7 +1586,7 @@ class World implements ChunkManager{
|
||||
$dynamicStateRead = false;
|
||||
}
|
||||
|
||||
if($addToCache and $relativeBlockHash !== null){
|
||||
if($addToCache && $relativeBlockHash !== null){
|
||||
$this->blockCache[$chunkHash][$relativeBlockHash] = $block;
|
||||
}
|
||||
|
||||
@ -1713,23 +1713,23 @@ class World implements ChunkManager{
|
||||
}
|
||||
|
||||
$drops = [];
|
||||
if($player === null or $player->hasFiniteResources()){
|
||||
if($player === null || $player->hasFiniteResources()){
|
||||
$drops = array_merge(...array_map(fn(Block $block) => $block->getDrops($item), $affectedBlocks));
|
||||
}
|
||||
|
||||
$xpDrop = 0;
|
||||
if($player !== null and $player->hasFiniteResources()){
|
||||
if($player !== null && $player->hasFiniteResources()){
|
||||
$xpDrop = array_sum(array_map(fn(Block $block) => $block->getXpDropForTool($item), $affectedBlocks));
|
||||
}
|
||||
|
||||
if($player !== null){
|
||||
$ev = new BlockBreakEvent($player, $target, $item, $player->isCreative(), $drops, $xpDrop);
|
||||
|
||||
if($target instanceof Air or ($player->isSurvival() and !$target->getBreakInfo()->isBreakable()) or $player->isSpectator()){
|
||||
if($target instanceof Air || ($player->isSurvival() && !$target->getBreakInfo()->isBreakable()) || $player->isSpectator()){
|
||||
$ev->cancel();
|
||||
}
|
||||
|
||||
if($player->isAdventure(true) and !$ev->isCancelled()){
|
||||
if($player->isAdventure(true) && !$ev->isCancelled()){
|
||||
$canBreak = false;
|
||||
$itemParser = LegacyStringToItemParser::getInstance();
|
||||
foreach($item->getCanDestroy() as $v){
|
||||
@ -1828,7 +1828,7 @@ class World implements ChunkManager{
|
||||
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled()){
|
||||
if((!$player->isSneaking() or $item->isNull()) and $blockClicked->onInteract($item, $face, $clickVector, $player)){
|
||||
if((!$player->isSneaking() || $item->isNull()) && $blockClicked->onInteract($item, $face, $clickVector, $player)){
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1843,7 +1843,7 @@ class World implements ChunkManager{
|
||||
return true;
|
||||
}
|
||||
|
||||
if($item->isNull() or !$item->canBePlaced()){
|
||||
if($item->isNull() || !$item->canBePlaced()){
|
||||
return false;
|
||||
}
|
||||
$hand = $item->getBlock($face);
|
||||
@ -1876,7 +1876,7 @@ class World implements ChunkManager{
|
||||
$ev->cancel();
|
||||
}
|
||||
|
||||
if($player->isAdventure(true) and !$ev->isCancelled()){
|
||||
if($player->isAdventure(true) && !$ev->isCancelled()){
|
||||
$canPlace = false;
|
||||
$itemParser = LegacyStringToItemParser::getInstance();
|
||||
foreach($item->getCanPlaceOn() as $v){
|
||||
@ -1941,9 +1941,9 @@ class World implements ChunkManager{
|
||||
public function getCollidingEntities(AxisAlignedBB $bb, ?Entity $entity = null) : array{
|
||||
$nearby = [];
|
||||
|
||||
if($entity === null or $entity->canCollide){
|
||||
if($entity === null || $entity->canCollide){
|
||||
foreach($this->getNearbyEntities($bb, $entity) as $ent){
|
||||
if($ent->canBeCollidedWith() and ($entity === null or $entity->canCollideWith($ent))){
|
||||
if($ent->canBeCollidedWith() && ($entity === null || $entity->canCollideWith($ent))){
|
||||
$nearby[] = $ent;
|
||||
}
|
||||
}
|
||||
@ -1971,7 +1971,7 @@ class World implements ChunkManager{
|
||||
continue;
|
||||
}
|
||||
foreach($this->getChunkEntities($x, $z) as $ent){
|
||||
if($ent !== $entity and $ent->boundingBox->intersectsWith($bb)){
|
||||
if($ent !== $entity && $ent->boundingBox->intersectsWith($bb)){
|
||||
$nearby[] = $ent;
|
||||
}
|
||||
}
|
||||
@ -2014,7 +2014,7 @@ class World implements ChunkManager{
|
||||
continue;
|
||||
}
|
||||
foreach($this->getChunkEntities($x, $z) as $entity){
|
||||
if(!($entity instanceof $entityType) or $entity->isFlaggedForDespawn() or (!$includeDead and !$entity->isAlive())){
|
||||
if(!($entity instanceof $entityType) || $entity->isFlaggedForDespawn() || (!$includeDead && !$entity->isAlive())){
|
||||
continue;
|
||||
}
|
||||
$distSq = $entity->getPosition()->distanceSquared($pos);
|
||||
@ -2173,7 +2173,7 @@ class World implements ChunkManager{
|
||||
public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk) : void{
|
||||
$chunkHash = World::chunkHash($chunkX, $chunkZ);
|
||||
$oldChunk = $this->loadChunk($chunkX, $chunkZ);
|
||||
if($oldChunk !== null and $oldChunk !== $chunk){
|
||||
if($oldChunk !== null && $oldChunk !== $chunk){
|
||||
$deletedTiles = 0;
|
||||
$transferredTiles = 0;
|
||||
foreach($oldChunk->getTiles() as $oldTile){
|
||||
@ -2439,7 +2439,7 @@ class World implements ChunkManager{
|
||||
}
|
||||
|
||||
public function isChunkInUse(int $x, int $z) : bool{
|
||||
return isset($this->chunkLoaders[$index = World::chunkHash($x, $z)]) and count($this->chunkLoaders[$index]) > 0;
|
||||
return isset($this->chunkLoaders[$index = World::chunkHash($x, $z)]) && count($this->chunkLoaders[$index]) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2582,7 +2582,7 @@ class World implements ChunkManager{
|
||||
}
|
||||
|
||||
public function unloadChunkRequest(int $x, int $z, bool $safe = true) : bool{
|
||||
if(($safe and $this->isChunkInUse($x, $z)) or $this->isSpawnChunk($x, $z)){
|
||||
if(($safe && $this->isChunkInUse($x, $z)) || $this->isSpawnChunk($x, $z)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2596,7 +2596,7 @@ class World implements ChunkManager{
|
||||
}
|
||||
|
||||
public function unloadChunk(int $x, int $z, bool $safe = true, bool $trySave = true) : bool{
|
||||
if($safe and $this->isChunkInUse($x, $z)){
|
||||
if($safe && $this->isChunkInUse($x, $z)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2619,7 +2619,7 @@ class World implements ChunkManager{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($trySave and $this->getAutoSave()){
|
||||
if($trySave && $this->getAutoSave()){
|
||||
$this->timings->syncChunkSave->startTiming();
|
||||
try{
|
||||
$this->provider->saveChunk($x, $z, new ChunkData(
|
||||
@ -2668,14 +2668,14 @@ class World implements ChunkManager{
|
||||
$spawnX = $spawn->x >> Chunk::COORD_BIT_SIZE;
|
||||
$spawnZ = $spawn->z >> Chunk::COORD_BIT_SIZE;
|
||||
|
||||
return abs($X - $spawnX) <= 1 and abs($Z - $spawnZ) <= 1;
|
||||
return abs($X - $spawnX) <= 1 && abs($Z - $spawnZ) <= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws WorldException if the terrain is not generated
|
||||
*/
|
||||
public function getSafeSpawn(?Vector3 $spawn = null) : Position{
|
||||
if(!($spawn instanceof Vector3) or $spawn->y < 1){
|
||||
if(!($spawn instanceof Vector3) || $spawn->y < 1){
|
||||
$spawn = $this->getSpawnLocation();
|
||||
}
|
||||
|
||||
@ -2700,7 +2700,7 @@ class World implements ChunkManager{
|
||||
}
|
||||
}
|
||||
|
||||
for(; $y >= $this->minY and $y < $max; ++$y){
|
||||
for(; $y >= $this->minY && $y < $max; ++$y){
|
||||
if(!$this->getBlockAt($x, $y + 1, $z)->isFullCube()){
|
||||
if(!$this->getBlockAt($x, $y, $z)->isFullCube()){
|
||||
return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y : $y, $spawn->z, $this);
|
||||
@ -2786,7 +2786,7 @@ class World implements ChunkManager{
|
||||
}
|
||||
|
||||
public function setDifficulty(int $difficulty) : void{
|
||||
if($difficulty < 0 or $difficulty > 3){
|
||||
if($difficulty < 0 || $difficulty > 3){
|
||||
throw new \InvalidArgumentException("Invalid difficulty level $difficulty");
|
||||
}
|
||||
$this->provider->getWorldData()->setDifficulty($difficulty);
|
||||
@ -3013,7 +3013,7 @@ class World implements ChunkManager{
|
||||
$this->setChunk($x + $relativeX, $z + $relativeZ, $adjacentChunk);
|
||||
}
|
||||
|
||||
if(($oldChunk === null or !$oldChunk->isPopulated()) and $chunk->isPopulated()){
|
||||
if(($oldChunk === null || !$oldChunk->isPopulated()) && $chunk->isPopulated()){
|
||||
(new ChunkPopulateEvent($this, $x, $z, $chunk))->call();
|
||||
|
||||
foreach($this->getChunkListeners($x, $z) as $listener){
|
||||
|
Reference in New Issue
Block a user