Unnecessary ":?" (2)

This commit is contained in:
Sunch 2024-08-17 20:08:11 +08:00
parent 0f26e45638
commit 69385e16f2
21 changed files with 36 additions and 48 deletions

View file

@ -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);

View file

@ -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";

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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){

View file

@ -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);

View file

@ -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));

View file

@ -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);

View file

@ -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));

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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));

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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");

View file

@ -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;
}
}
}

View file

@ -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){

View file

@ -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]);
}