diff --git a/src/Player.php b/src/Player.php index 6edcbe95..6743ac42 100755 --- a/src/Player.php +++ b/src/Player.php @@ -413,11 +413,7 @@ class Player{ * @return Item */ public function getSlot($slot){ - if(isset($this->inventory[(int) $slot])){ - return $this->inventory[(int) $slot]; - }else{ - return BlockAPI::getItem(AIR, 0, 0); - } + return $this->inventory[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); } /** @@ -724,11 +720,7 @@ class Player{ * @return Item */ public function getArmor($slot){ - if(isset($this->armor[(int) $slot])){ - return $this->armor[(int) $slot]; - }else{ - return BlockAPI::getItem(AIR, 0, 0); - } + return $this->armor[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); } public function setArmor($slot, Item $armor, $send = true){ @@ -779,7 +771,7 @@ class Player{ if($w === $data["tile"]){ $pk = new ContainerSetSlotPacket; $pk->windowid = $id; - $pk->slot = $data["slot"] + (isset($data["offset"]) ? $data["offset"] : 0); + $pk->slot = $data["slot"] + ($data["offset"] ?? 0); $pk->item = $data["slotdata"]; $this->dataPacket($pk); } @@ -1729,7 +1721,7 @@ class Player{ $pos = new Position($this->entity->x, $this->entity->y, $this->entity->z, $this->level); $pData = $this->data->get("position"); - $this->teleport($pos, isset($pData["yaw"]) ? $pData["yaw"] : false, isset($pData["pitch"]) ? $pData["pitch"] : false, true, true); + $this->teleport($pos, $pData["yaw"] ?? false, $pData["pitch"] ?? false, true, true); $this->entity->setHealth($this->data->get("health"), "spawn", true); $this->spawned = true; $this->server->api->player->spawnAllPlayers($this); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index d6de935d..bcc5825d 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -688,7 +688,7 @@ class PocketMinecraftServer{ E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED", ]; - $er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]] : $er["type"]; + $er["type"] = $errorConversion[$er["type"]] ?? $er["type"]; $dump .= "Error: " . var_export($er, true) . "\r\n\r\n"; if(stripos($er["file"], "plugin") !== false){ $dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n"; diff --git a/src/entity/Animal.php b/src/entity/Animal.php index ac978e70..b21aab0d 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -14,7 +14,7 @@ abstract class Animal extends Creature implements Ageable, Breedable{ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); - $this->setAge(isset($data["Age"]) ? $data["Age"] : 0); + $this->setAge($data["Age"] ?? 0); if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){ $this->setAge(-24000); } diff --git a/src/entity/Creature.php b/src/entity/Creature.php index 5a34b3d9..a8e97972 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -11,7 +11,7 @@ abstract class Creature extends Living{ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->inPanic = false; //force for now parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic"); + $this->setHealth($this->data["Health"] ?? 1, "generic"); $this->enableAutojump = true; $this->searchForClosestPlayers = true; } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 7d6db460..7c4a05e0 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -141,7 +141,7 @@ class Entity extends Position $this->isStatic = false; $this->name = ""; $this->gravity = 0.08; - $this->state = $this->data["State"] = isset($this->data["State"]) ? $this->data["State"] : 0; + $this->state = $this->data["State"] = $this->data["State"] ?? 0; $this->tickCounter = 0; $this->x = isset($this->data["x"]) ? (float) $this->data["x"] : 0; $this->y = isset($this->data["y"]) ? (float) $this->data["y"] : 0; @@ -151,7 +151,7 @@ class Entity extends Position $this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0; $this->speed = 0; $this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"] : 0; - $this->headYaw = isset($this->data["headYaw"]) ? $this->data["headYaw"] : $this->yaw; + $this->headYaw = $this->data["headYaw"] ?? $this->yaw; $this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"] : 0; $this->position = array( "level" => $this->level, @@ -178,9 +178,9 @@ class Entity extends Position break; case ENTITY_OBJECT: - $this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x; - $this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y; - $this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z; + $this->x = $this->data["TileX"] ?? $this->x; + $this->y = $this->data["TileY"] ?? $this->y; + $this->z = $this->data["TileZ"] ?? $this->z; $this->setHealth(1, "generic"); $this->stepHeight = false; $this->setSize(1, 1); diff --git a/src/entity/ai/EntityAI.php b/src/entity/ai/EntityAI.php index 1552ee27..a8c9d883 100644 --- a/src/entity/ai/EntityAI.php +++ b/src/entity/ai/EntityAI.php @@ -51,7 +51,7 @@ class EntityAI * @return TaskBase | false */ public function getTask($id){ - return isset($this->tasks[$id]) ? $this->tasks[$id] : false; + return $this->tasks[$id] ?? false; } public function isStarted($id){ diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 9ba51fba..f4e7e266 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -7,7 +7,7 @@ class Chicken extends Animal{ $this->timeUntilEgg = mt_rand(0,6000) + 6000; $this->setSize(0.4, 0.7); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic"); + $this->setHealth($this->data["Health"] ?? 4, "generic"); $this->setName('Chicken'); $this->setSpeed(0.25); diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 81fed1f7..441ff126 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -5,7 +5,7 @@ class Cow extends Animal{ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.9, 1.3); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); + $this->setHealth($this->data["Health"] ?? 10, "generic"); $this->setName("Cow"); $this->setSpeed(0.2); $this->ai->addTask(new TaskRandomWalk(0.8)); diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index 406b703f..d8bfe219 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -5,7 +5,7 @@ class Pig extends Animal implements Rideable{ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.9, 0.9); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic"); + $this->setHealth($this->data["Health"] ?? 10, "generic"); $this->server = ServerAPI::request(); $this->setName("Pig"); $this->setSpeed(0.25); diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index 4f1bbafa..d79c8701 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -7,10 +7,10 @@ class Sheep extends Animal{ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.9, 1.3); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic"); + $this->setHealth($this->data["Health"] ?? 8, "generic"); $this->setName("Sheep"); - $this->data["Sheared"] = isset($this->data["Sheared"]) ? $this->data["Sheared"] : 0; - $this->data["Color"] = isset($this->data["Color"]) ? $this->data["Color"] : $this->sheepColor(); + $this->data["Sheared"] = $this->data["Sheared"] ?? 0; + $this->data["Color"] = $this->data["Color"] ?? $this->sheepColor(); $this->setSpeed(0.25); $this->ai->addTask(new TaskRandomWalk(1.0)); diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index 2c29b45a..b1279f9c 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -7,7 +7,7 @@ class Creeper extends Monster{ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.6, 1.7); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 16, "generic"); + $this->setHealth($this->data["Health"] ?? 16, "generic"); $this->setName("Creeper"); $this->ignited = 0; $this->setSpeed(0.25); diff --git a/src/entity/monster/PigZombie.php b/src/entity/monster/PigZombie.php index 9f819ce0..812901ce 100644 --- a/src/entity/monster/PigZombie.php +++ b/src/entity/monster/PigZombie.php @@ -4,7 +4,7 @@ class PigZombie extends Monster{ //TODO extends zombie function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.3, 1.95); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic"); + $this->setHealth($this->data["Health"] ?? 12, "generic"); $this->setName("Pigman"); $this->setSpeed(0.25); $this->isImmuneToFire = true; diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index 0de4d329..52543a31 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -4,7 +4,7 @@ class Skeleton extends Monster{ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.6, 1.99); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); + $this->setHealth($this->data["Health"] ?? 10, "generic"); $this->setName("Skeleton"); $this->ai->removeTask("TaskAttackPlayer"); $this->setSpeed(0.25); diff --git a/src/entity/monster/Spider.php b/src/entity/monster/Spider.php index d52aeb4f..1752638f 100644 --- a/src/entity/monster/Spider.php +++ b/src/entity/monster/Spider.php @@ -5,7 +5,7 @@ class Spider extends Monster{ function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ $this->setSize(1.4, 0.9); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic"); + $this->setHealth($this->data["Health"] ?? 8, "generic"); $this->setName("Spider"); $this->setSpeed(0.3); $this->ai->addTask(new TaskRandomWalk(1.2)); diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index bfb42d54..bc38cf3a 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -4,7 +4,7 @@ class Zombie extends Monster{ function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ $this->setSize(0.6, 1.85); parent::__construct($level, $eid, $class, $type, $data); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic"); + $this->setHealth($this->data["Health"] ?? 12, "generic"); $this->setName("Zombie"); $this->setSpeed(0.23); diff --git a/src/entity/object/Minecart.php b/src/entity/object/Minecart.php index ee99b5d3..f76ddd96 100644 --- a/src/entity/object/Minecart.php +++ b/src/entity/object/Minecart.php @@ -59,9 +59,9 @@ class Minecart extends Vehicle{ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->canBeAttacked = true; - $this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x; - $this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y; - $this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z; + $this->x = $this->data["TileX"] ?? $this->x; + $this->y = $this->data["TileY"] ?? $this->y; + $this->z = $this->data["TileZ"] ?? $this->z; $this->setHealth(1, "generic"); //orig: 3 $this->setSize(0.98, 0.7); $this->yOffset = $this->height / 2; diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index a9cf1bfe..909843d6 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -5,9 +5,9 @@ class Painting extends Entity{ const TYPE = OBJECT_PAINTING; public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); - $this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x; - $this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y; - $this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z; + $this->x = $this->data["TileX"] ?? $this->x; + $this->y = $this->data["TileY"] ?? $this->y; + $this->z = $this->data["TileZ"] ?? $this->z; $this->setHealth(1, "generic"); $this->canBeAttacked = true; $this->width = 1; diff --git a/src/functions.php b/src/functions.php index a28959f0..fee2a0a4 100644 --- a/src/functions.php +++ b/src/functions.php @@ -118,11 +118,7 @@ function arg($name, $default = false){ $arguments = arguments($argv); } - if(isset($arguments["commands"][$name])){ - return $arguments["commands"][$name]; - }else{ - return $default; - } + return $arguments["commands"][$name] ?? $default; } function arguments($args){ @@ -217,7 +213,7 @@ function getTrace($start = 1){ foreach($trace[$i]["args"] as $name => $value){ $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", "; } - $messages[] = "#$j " . (isset($trace[$i]["file"]) ? $trace[$i]["file"] : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . $trace[$i]["type"] : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")"; + $messages[] = "#$j " . ($trace[$i]["file"] ?? "") . "(" . ($trace[$i]["line"] ?? "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . $trace[$i]["type"] : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")"; } return $messages; } @@ -243,7 +239,7 @@ function error_handler($errno, $errstr, $errfile, $errline){ E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED", ]; - $errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno; + $errno = $errorConversion[$errno] ?? $errno; console("[ERROR] A " . $errno . " error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0); foreach(getTrace() as $i => $line){ console("[TRACE] $line"); diff --git a/src/math/Matrix.php b/src/math/Matrix.php index a341f935..2684dbea 100644 --- a/src/math/Matrix.php +++ b/src/math/Matrix.php @@ -16,7 +16,7 @@ class Matrix implements ArrayAccess{ for($r = 0; $r < $this->rows; ++$r){ $this->matrix[$r] = []; for($c = 0; $c < $this->columns; ++$c){ - $this->matrix[$r][$c] = isset($m[$r][$c]) ? $m[$r][$c] : 0; + $this->matrix[$r][$c] = $m[$r][$c] ?? 0; } } } diff --git a/src/structure/Structure.php b/src/structure/Structure.php index a1e16c85..eaa51259 100644 --- a/src/structure/Structure.php +++ b/src/structure/Structure.php @@ -26,7 +26,7 @@ abstract class Structure{ $this->mapSymToID[$sym] = $id; } public function getMappingFor($sym){ - return isset($this->mapSymToID[$sym]) ? $this->mapSymToID[$sym] : Structure::MAP_NO_KEY; + return $this->mapSymToID[$sym] ?? Structure::MAP_NO_KEY; } protected function placeBlock($level, $sym, $tv){ diff --git a/src/world/Level.php b/src/world/Level.php index 17d0cb26..efc7078d 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -551,7 +551,7 @@ class Level{ $curChunkZ = (int)$e->z >> 4; $index = "$curChunkX $curChunkZ"; - if(isset($this->entityListPositioned[$index]) && isset($this->entityListPositioned[$index][$k])){ + if(isset($this->entityListPositioned[$index][$k])){ unset($this->entityListPositioned[$index][$k]); }