* More ??

* fix undefined variable
This commit is contained in:
Dylan K. Taylor
2016-11-30 10:07:37 +00:00
committed by GitHub
parent 43a36dba40
commit d6629d6843
15 changed files with 23 additions and 24 deletions

View File

@ -532,7 +532,7 @@ class Level implements ChunkManager, Metadatable{
* @return Player[]
*/
public function getChunkPlayers(int $chunkX, int $chunkZ) : array{
return isset($this->playerLoaders[$index = Level::chunkHash($chunkX, $chunkZ)]) ? $this->playerLoaders[$index] : [];
return $this->playerLoaders[Level::chunkHash($chunkX, $chunkZ)] ?? [];
}
/**
@ -544,7 +544,7 @@ class Level implements ChunkManager, Metadatable{
* @return ChunkLoader[]
*/
public function getChunkLoaders(int $chunkX, int $chunkZ) : array{
return isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)]) ? $this->chunkLoaders[$index] : [];
return $this->chunkLoaders[Level::chunkHash($chunkX, $chunkZ)] ?? [];
}
public function addChunkPacket(int $chunkX, int $chunkZ, DataPacket $packet){
@ -888,7 +888,7 @@ class Level implements ChunkManager, Metadatable{
$chunkZ = $loader->getZ() >> 4;
$index = Level::chunkHash($chunkX, $chunkZ);
$existingLoaders = max(0, isset($this->chunkTickList[$index]) ? $this->chunkTickList[$index] : 0);
$existingLoaders = max(0, $this->chunkTickList[$index] ?? 0);
$this->chunkTickList[$index] = $existingLoaders + 1;
for($chunk = 0; $chunk < $chunksPerLoader; ++$chunk){
$dx = mt_rand(-$randRange, $randRange);
@ -1769,7 +1769,7 @@ class Level implements ChunkManager, Metadatable{
* @return Entity
*/
public function getEntity(int $entityId){
return isset($this->entities[$entityId]) ? $this->entities[$entityId] : null;
return $this->entities[$entityId] ?? null;
}
/**
@ -1856,7 +1856,7 @@ class Level implements ChunkManager, Metadatable{
* @return Tile
*/
public function getTileById(int $tileId){
return isset($this->tiles[$tileId]) ? $this->tiles[$tileId] : null;
return $this->tiles[$tileId] ?? null;
}
/**

View File

@ -103,7 +103,7 @@ class SimpleChunkManager implements ChunkManager{
* @return FullChunk|null
*/
public function getChunk(int $chunkX, int $chunkZ){
return isset($this->chunks[$index = Level::chunkHash($chunkX, $chunkZ)]) ? $this->chunks[$index] : null;
return $this->chunks[Level::chunkHash($chunkX, $chunkZ)] ?? null;
}
/**

View File

@ -62,6 +62,6 @@ abstract class LevelProviderManager{
public static function getProviderByName($name){
$name = trim(strtolower($name));
return isset(self::$providers[$name]) ? self::$providers[$name] : null;
return self::$providers[$name] ?? null;
}
}

View File

@ -117,7 +117,7 @@ class Anvil extends McRegion{
* @return RegionLoader
*/
protected function getRegion($x, $z){
return isset($this->regions[$index = Level::chunkHash($x, $z)]) ? $this->regions[$index] : null;
return $this->regions[Level::chunkHash($x, $z)] ?? null;
}
/**

View File

@ -355,8 +355,7 @@ abstract class BaseFullChunk implements FullChunk{
}
public function getTile($x, $y, $z){
$index = ($z << 12) | ($x << 8) | $y;
return isset($this->tileList[$index]) ? $this->tileList[$index] : null;
return $this->tileList[($z << 12) | ($x << 8) | $y] ?? null;
}
public function isLoaded(){

View File

@ -220,7 +220,7 @@ class McRegion extends BaseLevelProvider{
}
public function unloadChunk($x, $z, $safe = true){
$chunk = isset($this->chunks[$index = Level::chunkHash($x, $z)]) ? $this->chunks[$index] : null;
$chunk = $this->chunks[$index = Level::chunkHash($x, $z)] ?? null;
if($chunk instanceof FullChunk and $chunk->unload(false, $safe)){
unset($this->chunks[$index]);
return true;
@ -246,7 +246,7 @@ class McRegion extends BaseLevelProvider{
* @return RegionLoader
*/
protected function getRegion($x, $z){
return isset($this->regions[$index = Level::chunkHash($x, $z)]) ? $this->regions[$index] : null;
return $this->regions[Level::chunkHash($x, $z)] ?? null;
}
/**

View File

@ -87,9 +87,9 @@ class Flat extends Generator{
$this->preset = $preset;
$preset = explode(";", $preset);
$version = (int) $preset[0];
$blocks = isset($preset[1]) ? $preset[1] : "";
$biome = isset($preset[2]) ? $preset[2] : 1;
$options = isset($preset[3]) ? $preset[3] : "";
$blocks = $preset[1] ?? "";
$biome = $preset[2] ?? 1;
$options = $preset[3] ?? "";
preg_match_all('#^(([0-9]*x|)([0-9]{1,3})(|:[0-9]{0,2}))$#m', str_replace(",", "\n", $blocks), $matches);
$y = 0;
$this->structure = [];

View File

@ -107,7 +107,7 @@ abstract class Biome{
* @return Biome
*/
public static function getBiome($id){
return isset(self::$biomes[$id]) ? self::$biomes[$id] : self::$biomes[self::OCEAN];
return self::$biomes[$id] ?? self::$biomes[self::OCEAN];
}
public function clearPopulators(){

View File

@ -81,6 +81,6 @@ class BiomeSelector{
$rainfall = (int) ($this->getRainfall($x, $z) * 63);
$biomeId = $this->map[$temperature + ($rainfall << 6)];
return isset($this->biomes[$biomeId]) ? $this->biomes[$biomeId] : $this->fallback;
return $this->biomes[$biomeId] ?? $this->fallback;
}
}