From d7d346a23795fb4e18763d1bda8015929feecd24 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 3 Jul 2023 06:49:12 +0300 Subject: [PATCH] goodbye php5, u wont be missed --- src/API/BlockAPI.php | 6 +++--- src/API/EntityAPI.php | 2 +- src/API/TimeAPI.php | 4 ++-- src/Player.php | 1 + src/dependencies.php | 4 ++-- src/entity/monster/Slime.php | 2 +- src/functions.php | 18 +++++------------- src/material/block/plant/CyanFlowerBlock.php | 2 +- src/material/block/solid/StoneBlock.php | 2 +- src/material/block/solid/WoolBlock.php | 2 +- src/material/item/generic/BucketItem.php | 2 +- src/material/item/generic/DyeItem.php | 2 +- src/pmf/PMFLevel.php | 2 +- src/structure/Structure.php | 2 +- src/world/Level.php | 2 +- src/world/generator/biome/BiomeSelector.php | 6 +++--- 16 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 84a66387..01a4835b 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -339,10 +339,10 @@ class BlockAPI{ } break; case "give": - $player = $this->server->api->player->get(nullsafe($args[0], "")); + $player = $this->server->api->player->get($args[0] ?? ""); if($player instanceof Player){ - $item = self::fromString(nullsafe($args[1], "")); + $item = self::fromString($args[1] ?? ""); if(($player->gamemode & 0x01) === 0x01){ $output .= "Player is in creative mode."; break; @@ -362,7 +362,7 @@ class BlockAPI{ $output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username; break; }else{ - $item = self::fromString(nullsafe($args[0], "")); + $item = self::fromString($args[0] ?? ""); if(!($issuer instanceof Player)){ return "You cant give an item to a non-player."; } diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index a4366886..b75dbcb1 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -175,7 +175,7 @@ class EntityAPI{ } public function get($eid){ - return nullsafe($this->entities[$eid], false); + return $this->entities[$eid] ?? false; } public function remove($eid){ diff --git a/src/API/TimeAPI.php b/src/API/TimeAPI.php index b02da668..51924611 100644 --- a/src/API/TimeAPI.php +++ b/src/API/TimeAPI.php @@ -31,7 +31,7 @@ class TimeAPI{ $p = strtolower(array_shift($args)); switch($p){ case "check": - if(substr(nullsafe($args[0], ""), 0, 2) === "w:"){ + if(substr($args[0] ?? "", 0, 2) === "w:"){ $levelName = preg_replace("/w:/", "", $args[0]); $level = $this->server->api->level->get($levelName); if($level instanceof Level){ @@ -44,7 +44,7 @@ class TimeAPI{ $output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n"; break; case "add": - if(substr(nullsafe($args[1], ""), 0, 2) === "w:"){ + if(substr($args[1] ?? "", 0, 2) === "w:"){ $levelName = preg_replace("/w:/", "", $args[1]); $level = $this->server->api->level->get($levelName); if($level instanceof Level){ diff --git a/src/Player.php b/src/Player.php index 264147d0..9e8e0453 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1274,6 +1274,7 @@ class Player{ if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){ return; } + console($packet->pid()); switch($packet->pid()){ case 0x01: break; diff --git a/src/dependencies.php b/src/dependencies.php index 2a5d091c..5258e999 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -17,8 +17,8 @@ set_error_handler("error_handler", E_ALL); $errors = 0; -if(version_compare("5.4.0", PHP_VERSION) > 0){ - console("[ERROR] Use PHP >= 5.4.0", true, true, 0); +if(version_compare("8.0.0", PHP_VERSION) > 0){ + console("[ERROR] Use PHP >= 8.0.0", true, true, 0); ++$errors; } diff --git a/src/entity/monster/Slime.php b/src/entity/monster/Slime.php index e6aa9b2b..c2e1a89c 100644 --- a/src/entity/monster/Slime.php +++ b/src/entity/monster/Slime.php @@ -11,7 +11,7 @@ class Slime extends Monster{ * SlimeSize = Slime::getSlimeSize(this); * return SlimeSize * SlimeSize; */ - $this->setSlimeSize(nullsafe($data["Size"], (1 << mt_rand(0, 2)))); + $this->setSlimeSize($data["Size"] ?? (1 << mt_rand(0, 2))); } public function getSlimeSize(){ diff --git a/src/functions.php b/src/functions.php index 49983ebb..e6ac065e 100644 --- a/src/functions.php +++ b/src/functions.php @@ -61,19 +61,11 @@ function kill($pid){ } } -if(version_compare(PHP_VERSION, '7.0.0') >= 0){ //php > 7.0 - eval(' - function nullsafe(&$a, $null){ - return $a ?? $null; - } - '); - -}else{ - eval(' - function nullsafe(&$value, $null){ - return isset($value) ? $value : $null; - } - '); //behavior will change if you replace ' with ". +/** + * @deprecated Use $expr ?? $null + */ +function nullsafe(&$a, $null){ + return $a ?? $null; } diff --git a/src/material/block/plant/CyanFlowerBlock.php b/src/material/block/plant/CyanFlowerBlock.php index 29c17505..c4c276ef 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -13,7 +13,7 @@ class CyanFlowerBlock extends FlowableBlock{ 8 => "Oxeye Daisy", ]; public function __construct($meta = 0){ - parent::__construct(CYAN_FLOWER, $meta, nullsafe(self::$names[$meta], "Poppy")); + parent::__construct(CYAN_FLOWER, $meta, self::$names[$meta] ?? "Poppy"); $this->hardness = 0; } diff --git a/src/material/block/solid/StoneBlock.php b/src/material/block/solid/StoneBlock.php index 1a002397..71c9d46d 100644 --- a/src/material/block/solid/StoneBlock.php +++ b/src/material/block/solid/StoneBlock.php @@ -13,7 +13,7 @@ class StoneBlock extends SolidBlock{ ]; public function __construct($meta = 0){ - parent::__construct(STONE, $meta, nullsafe(self::$names[$meta], "Stone")); + parent::__construct(STONE, $meta, self::$names[$meta] ?? "Stone"); $this->hardness = 30; } diff --git a/src/material/block/solid/WoolBlock.php b/src/material/block/solid/WoolBlock.php index 2e4f9b8f..b891858e 100644 --- a/src/material/block/solid/WoolBlock.php +++ b/src/material/block/solid/WoolBlock.php @@ -22,7 +22,7 @@ class WoolBlock extends SolidBlock{ ); public function __construct($meta = 0){ - parent::__construct(WOOL, $meta, nullsafe(self::$names[$meta], "Wool")); + parent::__construct(WOOL, $meta, self::$names[$meta] ?? "Wool"); $this->hardness = 4; } diff --git a/src/material/item/generic/BucketItem.php b/src/material/item/generic/BucketItem.php index 325659d8..fd21de90 100644 --- a/src/material/item/generic/BucketItem.php +++ b/src/material/item/generic/BucketItem.php @@ -8,7 +8,7 @@ class BucketItem extends Item{ 10 => "Lava Bucket" ); public function __construct($meta = 0, $count = 1){ - parent::__construct(BUCKET, $meta, $count, nullsafe(self::$possiblenames[$meta], "Bucket")); + parent::__construct(BUCKET, $meta, $count, self::$possiblenames[$meta] ?? "Bucket"); $this->isActivable = true; $this->maxStackSize = 1; } diff --git a/src/material/item/generic/DyeItem.php b/src/material/item/generic/DyeItem.php index d3e2f1d6..50625af9 100755 --- a/src/material/item/generic/DyeItem.php +++ b/src/material/item/generic/DyeItem.php @@ -21,6 +21,6 @@ class DyeItem extends Item{ ); public function __construct($meta = 0, $count = 1){ - parent::__construct(DYE, $meta, $count, nullsafe(self::$names[$meta], "Dye")); + parent::__construct(DYE, $meta, $count, self::$names[$meta] ?? "Dye"); } } diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 5b91fb31..f49f959a 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -444,7 +444,7 @@ class PMFLevel extends PMF{ $X = $x >> 4; $Z = $z >> 4; $index = $this->getIndex($X, $Z); - return nullsafe($this->chunks[$index], 0); + return $this->chunks[$index] ?? 0; } public function getBlockID($x, $y, $z){ diff --git a/src/structure/Structure.php b/src/structure/Structure.php index b1dbca31..6ad313a8 100644 --- a/src/structure/Structure.php +++ b/src/structure/Structure.php @@ -27,7 +27,7 @@ abstract class Structure{ } protected function getMappingFor($char){ - return nullsafe($this->map[$char], self::MAP_NO_KEY); + return $this->map[$char] ?? self::MAP_NO_KEY; } protected function placeBlock(Level $level, $char, $vector){ diff --git a/src/world/Level.php b/src/world/Level.php index 835bd492..d9f1bc5b 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -395,7 +395,7 @@ class Level{ foreach($this->usedChunks as $c => $eids){ $xz = explode(".", $c); //bad idea, TODO use better indexes foreach($eids as $cid => $_){ - $p = nullsafe($this->server->clients[$cid], false); + $p = $this->server->clients[$cid] ?? false; if($p instanceof Player){ $dist = abs($xz[0] - ($p->entity->x >> 4)) + abs($xz[1] - ($p->entity->z >> 4)); if($dist > 8){ diff --git a/src/world/generator/biome/BiomeSelector.php b/src/world/generator/biome/BiomeSelector.php index af91236f..0de1f1a2 100644 --- a/src/world/generator/biome/BiomeSelector.php +++ b/src/world/generator/biome/BiomeSelector.php @@ -33,7 +33,7 @@ class BiomeSelector * @return Biome | false */ public static function get($id){ - return nullsafe(self::$biomes[$id], false); + return self::$biomes[$id] ?? false; } public function generateBiomeLookup(){ @@ -92,8 +92,8 @@ class BiomeSelector $temperature = (int) ($this->getTemperature($x, $z) * 63); $rainfall = (int) ($this->getRainfall($x, $z) * 63); - $biomeId = nullsafe($this->map[$temperature + ($rainfall << 6)], -1); - return nullsafe(self::$biomes[$biomeId], $this->fallback); + $biomeId = $this->map[$temperature + ($rainfall << 6)] ?? -1; + return self::$biomes[$biomeId] ?? $this->fallback; } }