From 4630481d5485eb5ae1479b2bbe97c3897c12c429 Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 19:58:16 +0800 Subject: [PATCH 01/12] Unnecessary arguments in the if expression --- src/API/AchievementAPI.php | 4 ++-- src/API/ServerAPI.php | 4 ++-- src/PocketMinecraftServer.php | 4 ++-- src/dependencies.php | 2 +- src/network/protocol/packet/SetTimePacket.php | 2 +- src/network/query/QueryHandler.php | 2 +- src/network/raknet/RakNetParser.php | 2 +- src/utils/StopMessageThread.php | 2 +- src/world/Level.php | 4 ++-- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/API/AchievementAPI.php b/src/API/AchievementAPI.php index e28c5394..beabe308 100644 --- a/src/API/AchievementAPI.php +++ b/src/API/AchievementAPI.php @@ -130,7 +130,7 @@ class AchievementAPI{ return false; } - if(!isset($player->achievements[$achievementId]) or $player->achievements[$achievementId] == false){ + if(!isset($player->achievements[$achievementId]) or !$player->achievements[$achievementId]){ return false; } return true; @@ -140,7 +140,7 @@ class AchievementAPI{ if(isset(self::$achievements[$achievementId])){ $result = ServerAPI::request()->api->dhandle("achievement.broadcast", ["player" => $player, "achievementId" => $achievementId]); if($result !== false and $result !== true){ - if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){ + if(ServerAPI::request()->api->getProperty("announce-player-achievements")){ ServerAPI::request()->api->chat->broadcast($player->username . " has just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]"); }else{ $player->sendChat("You have just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]"); diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 55a3af1e..b990a8c6 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -152,7 +152,7 @@ class ServerAPI{ //define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals"); MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs"); - if($this->getProperty("upnp-forwarding") == true){ + if($this->getProperty("upnp-forwarding")){ console("[INFO] [UPnP] Trying to port forward..."); UPnP_PortForward($this->getProperty("server-port")); } @@ -245,7 +245,7 @@ class ServerAPI{ public function setProperty($name, $value, $save = true){ $this->config->set($name, $value); - if($save == true){ + if($save){ $this->writeProperties(); } $this->loadProperties(); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index c19754a7..d6de935d 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -106,7 +106,7 @@ class PocketMinecraftServer{ if(self::$FORCE_20_TPS){ ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!"); } - if($this->extraprops->get("discord-msg") == true){ + if($this->extraprops->get("discord-msg")){ if($this->extraprops->get("discord-webhook-url") !== "none"){ console("[INFO] Discord Logger is enabled."); }else{ @@ -226,7 +226,7 @@ class PocketMinecraftServer{ } public function send2Discord($msg){ - if($this->extraprops->get("discord-msg") == true and $this->extraprops->get("discord-webhook-url") !== "none"){ + if($this->extraprops->get("discord-msg") and $this->extraprops->get("discord-webhook-url") !== "none"){ $url = $this->extraprops->get("discord-webhook-url"); $name = $this->extraprops->get("discord-bot-name"); $this->asyncOperation(ASYNC_CURL_POST, [ diff --git a/src/dependencies.php b/src/dependencies.php index 5554945f..0466394e 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -130,7 +130,7 @@ ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OP define("SOURCE_SHA1SUM", bin2hex($sha1sum)); /***REM_START***/ -if(!file_exists(DATA_PATH . "server.properties") and arg("no-wizard", false) != true){ +if(!file_exists(DATA_PATH . "server.properties") and !arg("no-wizard", false)){ $installer = new Installer(); } /***REM_END***/ diff --git a/src/network/protocol/packet/SetTimePacket.php b/src/network/protocol/packet/SetTimePacket.php index b78c9f94..302afd9e 100644 --- a/src/network/protocol/packet/SetTimePacket.php +++ b/src/network/protocol/packet/SetTimePacket.php @@ -15,7 +15,7 @@ class SetTimePacket extends RakNetDataPacket{ public function encode(){ $this->reset(); $this->putInt($this->time); - $this->putByte($this->started == true ? 0x80:0x00); + $this->putByte($this->started ? 0x80:0x00); } } \ No newline at end of file diff --git a/src/network/query/QueryHandler.php b/src/network/query/QueryHandler.php index 8b92ec1f..7530d3b6 100644 --- a/src/network/query/QueryHandler.php +++ b/src/network/query/QueryHandler.php @@ -39,7 +39,7 @@ class QueryHandler{ public function regenerateInfo(){ $str = ""; $plist = "NostalgiaCore " . MAJOR_VERSION; - if($this->server->extraprops->get("query-plugins") == true){ + if($this->server->extraprops->get("query-plugins")){ $pl = $this->server->api->plugin->getList(); if(count($pl) > 0){ $plist .= ":"; diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index c87bef72..0d6b8b29 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -143,7 +143,7 @@ class RakNetParser{ $orderChannel = false; } - if($hasSplit == true){ + if($hasSplit){ $splitCount = $this->getInt(); $splitID = $this->getShort(); $splitIndex = $this->getInt(); diff --git a/src/utils/StopMessageThread.php b/src/utils/StopMessageThread.php index 157a85ec..2c07172e 100644 --- a/src/utils/StopMessageThread.php +++ b/src/utils/StopMessageThread.php @@ -4,7 +4,7 @@ class StopMessageThread extends Thread { private $page, $msg; public function __construct(PocketMinecraftServer $server, $msg){ - if($server->extraprops->get("discord-msg") == true and ($this->page = $server->extraprops->get("discord-webhook-url")) !== "none"){ + if($server->extraprops->get("discord-msg") and ($this->page = $server->extraprops->get("discord-webhook-url")) !== "none"){ $this->msg = $server->extraprops->get("discord-ru-smiles") ? str_replace("@", " ", str_replace("Ы", "<:ru_cool:960113011383738369>", str_replace("Ь", "<:ru_cry:960112920346390548>", str_replace("Ъ", "<:ru_happy:960112868601237504>", $msg)))) : str_replace("@", "", $msg); $this->name = $server->extraprops->get("discord-bot-name"); $this->start(); diff --git a/src/world/Level.php b/src/world/Level.php index 639c127d..17d0cb26 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -376,7 +376,7 @@ class Level{ if(count($this->players) == 0) return false; if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla foreach($this->players as $p){ - if($p->isSleeping == false || $p->sleepingTime < 100){ + if(!$p->isSleeping || $p->sleepingTime < 100){ return false; } } @@ -906,7 +906,7 @@ class Level{ return false; } $now = microtime(true); - if($this->stopTime == true){ + if($this->stopTime){ $time = $this->startTime; }else{ $time = $this->startTime + ($now - $this->startCheck) * 20; From 4eb6bd14a2defcb069063172e1ecc85a33a697ed Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:01:40 +0800 Subject: [PATCH 02/12] Unnecessary "?:" --- src/dependencies.php | 2 +- src/entity/Entity.php | 2 +- src/material/Block.php | 6 +++--- src/utils/RailLogic.php | 2 +- src/utils/Utils.php | 2 +- src/world/MobSpawner.php | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/dependencies.php b/src/dependencies.php index 0466394e..097eaed1 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -7,7 +7,7 @@ require_once(FILE_PATH . "/src/functions.php"); /***REM_END***/ define("DATA_PATH", realpath(arg("data-path", FILE_PATH)) . "/"); -if(arg("enable-ansi", strpos(strtoupper(php_uname("s")), "WIN") === 0 ? false : true) === true and arg("disable-ansi", false) !== true){ +if(arg("enable-ansi", !(strpos(strtoupper(php_uname("s")), "WIN") === 0)) === true and arg("disable-ansi", false) !== true){ define("ENABLE_ANSI", true); }else{ define("ENABLE_ANSI", false); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index eba2d156..7211dd2c 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -383,7 +383,7 @@ class Entity extends Position * @return boolean */ public function isPickable(){ - return $this->isPlayer() ? !$this->dead : false; + return $this->isPlayer() && !$this->dead; } public function handleLavaMovement(){ //TODO maybe try merging with water? diff --git a/src/material/Block.php b/src/material/Block.php index dc4653b1..459c1e91 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -163,15 +163,15 @@ abstract class Block extends Position{ } public static function containsX($id, $v){ - return $v == null ? false : $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; + return !($v == null) && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; } public static function containsY($id, $v){ - return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; + return !($v == null) && $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; } public static function containsZ($id, $v){ - return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id]; + return !($v == null) && $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id]; } public static function updateShape(Level $level, $x, $y, $z){ diff --git a/src/utils/RailLogic.php b/src/utils/RailLogic.php index 2352d4e8..6f293a5f 100644 --- a/src/utils/RailLogic.php +++ b/src/utils/RailLogic.php @@ -63,7 +63,7 @@ class RailLogic } public function canConnectTo(RailLogic $rail){ - return $this->connectsTo($rail) ? true : (count($this->railPositions) == 2 ? false : (empty($this->railPositions) ? true : true)); + return $this->connectsTo($rail) || ((count($this->railPositions) == 2 ? false : (empty($this->railPositions) ? true : true))); } public function hasNeighborRail($x, $y, $z){ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 2131b6e2..98f3666d 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -581,7 +581,7 @@ class Utils{ } public static function readBool($b){ - return Utils::readByte($b, false) === 0 ? false : true; + return !(Utils::readByte($b, false) === 0); } public static function writeBool($b){ diff --git a/src/world/MobSpawner.php b/src/world/MobSpawner.php index 45f6125d..48d63306 100644 --- a/src/world/MobSpawner.php +++ b/src/world/MobSpawner.php @@ -133,8 +133,8 @@ class MobSpawner{ $b1 = $this->level->level->getBlockID($x, $y - 1, $z); if( !StaticBlock::getIsSolid($b) && !StaticBlock::getIsLiquid($b) && - (StaticBlock::getIsSolid($b1) && ($grassOnly ? $b1 === GRASS : true) && - ($highMob ? !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2) : true)) + (StaticBlock::getIsSolid($b1) && (!$grassOnly || $b1 === GRASS) && + (!$highMob || !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2))) ){ $allowed[] = $y; } From e2dae67a1c468800fa905fabe483d9079174c1e6 Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:02:17 +0800 Subject: [PATCH 03/12] Unnecessary ";" --- src/API/PluginAPI.php | 4 ++-- src/material/block/StairBlock.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index f50e4f2e..a9eb0158 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -55,8 +55,8 @@ class PluginAPI extends stdClass{ return; } foreach($this->plugins as $p){ - if(method_exists($p[0], "__destruct")){$p[0]->__destruct();}; - } + if(method_exists($p[0], "__destruct")){$p[0]->__destruct();} + } unset($this->plugins); } diff --git a/src/material/block/StairBlock.php b/src/material/block/StairBlock.php index 7cf46948..4a29e2a4 100644 --- a/src/material/block/StairBlock.php +++ b/src/material/block/StairBlock.php @@ -80,7 +80,7 @@ class StairBlock extends TransparentBlock{ for($v15 = 0; $v15 < /*count($v11}*/ 2; ++$v15){ $v16 = $v11[$v15]; if($v16 == $v12){ - ; //wat + //wat } } From d3f53868122d1414244b7a3a72d5acc2ebe8f8fe Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:05:28 +0800 Subject: [PATCH 04/12] Unnecessary return/continue --- src/Player.php | 3 +-- src/entity/Entity.php | 3 +-- src/entity/object/Arrow.php | 3 +-- src/functions.php | 3 +-- src/material/block/solid/GrassBlock.php | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Player.php b/src/Player.php index ba0f6879..6edcbe95 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1037,8 +1037,7 @@ class Player{ } } } - return; - reset_spawn_pos: + reset_spawn_pos: $this->spawnPosition = $this->server->api->level->getDefault()->getSpawn(); } } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 7211dd2c..7d6db460 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1496,8 +1496,7 @@ class Entity extends Position { if($this->class === ENTITY_PLAYER){ $this->player->teleport(new Vector3($this->x, $this->y, $this->z), false, false, true, false); - return; - } + } } public function moveEntityWithOffset($oX, $oY, $oZ) diff --git a/src/entity/object/Arrow.php b/src/entity/object/Arrow.php index c2213d94..1b84c920 100644 --- a/src/entity/object/Arrow.php +++ b/src/entity/object/Arrow.php @@ -139,8 +139,7 @@ class Arrow extends Entity{ ++$this->groundTicks; if($this->groundTicks >= 1200){ //TODO customizeable? $this->close(); - return; - } + } }else{ $this->inGround = false; $this->speedX *= lcg_value() * 0.2; diff --git a/src/functions.php b/src/functions.php index 90632ecd..a28959f0 100644 --- a/src/functions.php +++ b/src/functions.php @@ -162,9 +162,8 @@ function arguments($args){ } $ret['input'][] = $arg; - continue; - } + } return $ret; } diff --git a/src/material/block/solid/GrassBlock.php b/src/material/block/solid/GrassBlock.php index fdeee837..66d4ddbe 100644 --- a/src/material/block/solid/GrassBlock.php +++ b/src/material/block/solid/GrassBlock.php @@ -45,8 +45,7 @@ class GrassBlock extends SolidBlock{ ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(295,0,1)); return; } - return; - } + } public static function onRandomTick(Level $level, $x, $y, $z){ if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z)) && mt_rand(0, 2) == 1){ $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0); From 9eeaa9600f5d8c88d0b23b58fdcb2f8175bbd327 Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:06:27 +0800 Subject: [PATCH 05/12] Unnecessary method overrides --- src/entity/animal/Chicken.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 054fd647..9ba51fba 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -36,12 +36,8 @@ class Chicken extends Animal{ } public function fall(){} //chickens have no fall dmg? - - public function update($now){ - parent::update($now); - } - - public function dropAnEgg(){ + + public function dropAnEgg(){ if($this->closed){ return; } From 0f26e456388ba2cdebd61329253a22a1c20ee271 Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:07:08 +0800 Subject: [PATCH 06/12] use min() and max() --- src/utils/LightUtils.php | 2 +- src/utils/MersenneTwister.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/LightUtils.php b/src/utils/LightUtils.php index 876db487..83820d8f 100644 --- a/src/utils/LightUtils.php +++ b/src/utils/LightUtils.php @@ -15,6 +15,6 @@ class LightUtils{ $diffZ = ($source->z - $block->z); $distance = $diffX*$diffX + $diffY*$diffY + $diffZ*$diffZ; $result = floor($source->getMaxLightValue() - $distance); - return $result <= 0 ? 0 : $result; + return max($result, 0); } } \ No newline at end of file diff --git a/src/utils/MersenneTwister.php b/src/utils/MersenneTwister.php index 194d54f8..e35c7f25 100644 --- a/src/utils/MersenneTwister.php +++ b/src/utils/MersenneTwister.php @@ -125,7 +125,7 @@ class MersenneTwister{ $this->init_with_integer(19650218); $i = 1; $j = 0; - $k = (N > $key_length ? N : $key_length); + $k = (max(N, $key_length)); for(; $k; $k--){ $mt[$i] = add_3($mt[$i] ^ mul_by_1664525($mt[$i - 1] ^ (($mt[$i - 1] >> 30) & 3)), From 69385e16f2895f4f61113f1ca234d24140c2a797 Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:08:11 +0800 Subject: [PATCH 07/12] Unnecessary ":?" (2) --- src/Player.php | 16 ++++------------ src/PocketMinecraftServer.php | 2 +- src/entity/Animal.php | 2 +- src/entity/Creature.php | 2 +- src/entity/Entity.php | 10 +++++----- src/entity/ai/EntityAI.php | 2 +- src/entity/animal/Chicken.php | 2 +- src/entity/animal/Cow.php | 2 +- src/entity/animal/Pig.php | 2 +- src/entity/animal/Sheep.php | 6 +++--- src/entity/monster/Creeper.php | 2 +- src/entity/monster/PigZombie.php | 2 +- src/entity/monster/Skeleton.php | 2 +- src/entity/monster/Spider.php | 2 +- src/entity/monster/Zombie.php | 2 +- src/entity/object/Minecart.php | 6 +++--- src/entity/object/Painting.php | 6 +++--- src/functions.php | 10 +++------- src/math/Matrix.php | 2 +- src/structure/Structure.php | 2 +- src/world/Level.php | 2 +- 21 files changed, 36 insertions(+), 48 deletions(-) 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]); } From 1275a4558c64c7aba1a0328daa22936066225e02 Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:11:55 +0800 Subject: [PATCH 08/12] PHP8: new str_* function --- src/API/PlayerAPI.php | 6 +++--- src/API/TimeAPI.php | 8 ++++---- src/PocketMinecraftServer.php | 2 +- src/config.php | 4 ++-- src/dependencies.php | 2 +- src/functions.php | 4 ++-- src/utils/Utils.php | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 8c3272f9..b4908833 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -190,8 +190,8 @@ class PlayerAPI{ } break; case "tp": - if(count($args) <= 2 or substr($args[0], 0, 2) === "w:" or substr($args[1], 0, 2) === "w:"){ - if((!isset($args[1]) or substr($args[0], 0, 2) === "w:") and isset($args[0]) and ($issuer instanceof Player)){ + if(count($args) <= 2 or str_starts_with($args[0], "w:") or str_starts_with($args[1], "w:")){ + if((!isset($args[1]) or str_starts_with($args[0], "w:")) and isset($args[0]) and ($issuer instanceof Player)){ $name = $issuer->username; $target = implode(" ", $args); }elseif(isset($args[1]) and isset($args[0])){ @@ -297,7 +297,7 @@ class PlayerAPI{ } public function teleport(&$name, &$target){ - if(substr($target, 0, 2) === "w:"){ + if(str_starts_with($target, "w:")){ $lv = $this->server->api->level->get(substr($target, 2)); if($lv instanceof Level){ $origin = $this->get($name); diff --git a/src/API/TimeAPI.php b/src/API/TimeAPI.php index 51924611..225f4046 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($args[0] ?? "", 0, 2) === "w:"){ + if(str_starts_with($args[0] ?? "", "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($args[1] ?? "", 0, 2) === "w:"){ + if(str_starts_with($args[1] ?? "", "w:")){ $levelName = preg_replace("/w:/", "", $args[1]); $level = $this->server->api->level->get($levelName); if($level instanceof Level){ @@ -65,7 +65,7 @@ class TimeAPI{ $output .= "Added $addTime ticks" . $world . "\n"; break; case "set": - if(isset($args[1]) and substr($args[1], 0, 2) === "w:"){ + if(isset($args[1]) and str_starts_with($args[1], "w:")){ $levelName = preg_replace("/w:/", "", $args[1]); $level = $this->server->api->level->get($levelName); if($level instanceof Level){ @@ -92,7 +92,7 @@ class TimeAPI{ case "day": case "sunset": case "night": - if(count($args) > 1 && substr($args[1], 0, 2) === "w:"){ + if(count($args) > 1 && str_starts_with($args[1], "w:")){ $levelName = preg_replace("/w:/", "", $args[1]); $level = $this->server->api->level->get($levelName); if($level instanceof Level){ diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index bcc5825d..54e02ad7 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -548,7 +548,7 @@ class PocketMinecraftServer{ $this->custom["times_" . $CID] = 0; } $ln = 15; - if($this->description == "" or substr($this->description, -1) != " "){ + if($this->description == "" or !str_ends_with($this->description, " ")){ $this->description .= " "; } $txt = substr($this->description, $this->custom["times_" . $CID], $ln); diff --git a/src/config.php b/src/config.php index 5b9eceb8..09c6681e 100644 --- a/src/config.php +++ b/src/config.php @@ -4,7 +4,7 @@ set_time_limit(0); if(ini_get("date.timezone") == ""){ //No Timezone set date_default_timezone_set("GMT"); - if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){ + if(str_contains(" " . strtoupper(php_uname("s")), " WIN")){ $time = time(); $time -= $time % 60; //Example: USA @@ -24,7 +24,7 @@ if(ini_get("date.timezone") == ""){ //No Timezone set date_default_timezone_set($d); }else{ $d = @date_default_timezone_get(); - if(strpos($d, "/") === false){ + if(!str_contains($d, "/")){ $d = timezone_name_from_abbr($d); @ini_set("date.timezone", $d); date_default_timezone_set($d); diff --git a/src/dependencies.php b/src/dependencies.php index 097eaed1..0e6613e7 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -120,7 +120,7 @@ $inc = get_included_files(); $inc[] = array_shift($inc); $srcdir = realpath(FILE_PATH . "src/"); foreach($inc as $s){ - if(strpos(realpath(dirname($s)), $srcdir) === false and strtolower(basename($s)) !== "pocketmine-mp.php"){ + if(!str_contains(realpath(dirname($s)), $srcdir) and strtolower(basename($s)) !== "pocketmine-mp.php"){ continue; } $sha1sum ^= sha1_file($s, true); diff --git a/src/functions.php b/src/functions.php index fee2a0a4..cf512b7b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -140,7 +140,7 @@ function arguments($args){ foreach($args as $arg){ // Is it a command? (prefixed with --) - if(substr($arg, 0, 2) === '--'){ + if(str_starts_with($arg, '--')){ $value = preg_split('/[= ]/', $arg, 2); $com = substr(array_shift($value), 2); @@ -152,7 +152,7 @@ function arguments($args){ } // Is it a flag? (prefixed with -) - if(substr($arg, 0, 1) === '-'){ + if(str_starts_with($arg, '-')){ $ret['flags'][] = substr($arg, 1); continue; } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 98f3666d..bd418cc2 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -87,7 +87,7 @@ class Utils{ * PHP8 has internal function for doing it: {@link str_ends_with} */ public static function endsWith($str, $check) { - return substr($str, -strlen($check)) === $check; + return str_ends_with($str, $check); } public static function hasEmoji($s){ @@ -148,7 +148,7 @@ class Utils{ public static function getOS(){ $uname = php_uname("s"); if(stripos($uname, "Darwin") !== false){ - if(strpos(php_uname("m"), "iP") === 0){ + if(str_starts_with(php_uname("m"), "iP")){ return "ios"; }else{ return "mac"; From f74e6e0638b97a255c48dd881cff0c52c78633ee Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Sat, 17 Aug 2024 20:12:37 +0800 Subject: [PATCH 09/12] PHP8: use match function --- src/API/LevelAPI.php | 16 +++---- src/API/PlayerAPI.php | 44 +++++-------------- src/functions.php | 26 +++-------- src/material/Item.php | 22 ++++------ src/material/block/nonfull/IronDoorBlock.php | 22 ++++------ src/material/block/nonfull/SlabBlock.php | 22 ++++------ src/material/block/nonfull/WoodSlabBlock.php | 22 ++++------ .../block/nonfull/stairs/WoodStairsBlock.php | 22 ++++------ src/material/block/ore/CoalOreBlock.php | 22 ++++------ src/material/block/ore/DiamondOreBlock.php | 13 +++--- .../block/ore/GlowingRedstoneOreBlock.php | 13 +++--- src/material/block/ore/GoldOreBlock.php | 13 +++--- src/material/block/ore/IronOreBlock.php | 16 +++---- src/material/block/ore/LapisOreBlock.php | 16 +++---- src/material/block/solid/BricksBlock.php | 22 ++++------ .../block/solid/BurningFurnaceBlock.php | 22 ++++------ src/material/block/solid/CoalBlock.php | 22 ++++------ src/material/block/solid/CobblestoneBlock.php | 22 ++++------ src/material/block/solid/DiamondBlock.php | 13 +++--- src/material/block/solid/DoubleSlabBlock.php | 22 ++++------ .../block/solid/DoubleWoodSlabBlock.php | 22 ++++------ src/material/block/solid/GoldBlock.php | 13 +++--- src/material/block/solid/IceBlock.php | 22 ++++------ src/material/block/solid/IronBlock.php | 16 +++---- src/material/block/solid/LapisBlock.php | 16 +++---- src/material/block/solid/MossStoneBlock.php | 22 ++++------ .../block/solid/NetherBricksBlock.php | 22 ++++------ src/material/block/solid/NetherrackBlock.php | 22 ++++------ src/material/block/solid/QuartzBlock.php | 22 ++++------ src/material/block/solid/SandstoneBlock.php | 22 ++++------ src/material/block/solid/StoneBlock.php | 22 ++++------ src/material/block/solid/StoneBricksBlock.php | 22 ++++------ src/material/item/base/ItemAxe.php | 22 ++++------ src/material/item/base/ItemHoe.php | 22 ++++------ src/material/item/base/ItemPickaxe.php | 22 ++++------ src/material/item/base/ItemShovel.php | 22 ++++------ src/material/item/base/ItemSword.php | 22 ++++------ src/math/Matrix.php | 17 +++---- src/math/Vector3.php | 25 ++++------- src/network/raknet/RakNetInfo.php | 36 ++------------- src/utils/Utils.php | 31 +++---------- 41 files changed, 300 insertions(+), 574 deletions(-) diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index b07f9d6a..380c3884 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -145,17 +145,11 @@ class LevelAPI{ if($generator !== false and class_exists($generator)){ $generator = new $generator($options); }else{ - switch(strtoupper($this->server->api->getProperty("level-type"))){ - case "FLAT": - $generator = new SuperflatGenerator($options); - break; - case "VANILLA": - $generator = new VanillaGenerator($options); - break; - default: - $generator = new TemporalGenerator($options); - break; - } + $generator = match (strtoupper($this->server->api->getProperty("level-type"))) { + "FLAT" => new SuperflatGenerator($options), + "VANILLA" => new VanillaGenerator($options), + default => new TemporalGenerator($options), + }; } $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed); $gen->generate(); diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index b4908833..e817e90c 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -57,38 +57,18 @@ class PlayerAPI{ } } }else{ - switch($data["cause"]){ - case "cactus": - $message = " was pricked to death"; - break; - case "lava": - $message = " tried to swim in lava"; - break; - case "fire": - $message = " went up in flames"; - break; - case "burning": - $message = " burned to death"; - break; - case "suffocation": - $message = " suffocated in a wall"; - break; - case "water": - $message = " drowned"; - break; - case "void": - $message = " fell out of the world"; - break; - case "fall": - $message = " hit the ground too hard"; - break; - case "explosion": - $message = " blew up"; - break; - default: - $message = " died"; - break; - } + $message = match ($data["cause"]) { + "cactus" => " was pricked to death", + "lava" => " tried to swim in lava", + "fire" => " went up in flames", + "burning" => " burned to death", + "suffocation" => " suffocated in a wall", + "water" => " drowned", + "void" => " fell out of the world", + "fall" => " hit the ground too hard", + "explosion" => " blew up", + default => " died", + }; } $this->server->api->chat->broadcast($data["player"]->username . $message); return true; diff --git a/src/functions.php b/src/functions.php index cf512b7b..4717289a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -175,25 +175,13 @@ function console($message, $EOL = true, $log = true, $level = 1){ if(ENABLE_ANSI === true){ $add = ""; if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){ - switch($matches[1]){ - case "ERROR": - case "SEVERE": - $add .= FORMAT_RED; - break; - case "INTERNAL": - case "DEBUG": - $add .= FORMAT_WHITE; - break; - case "WARNING": - $add .= FORMAT_YELLOW; - break; - case "NOTICE": - $add .= FORMAT_AQUA; - break; - default: - $add .= FORMAT_GRAY; - break; - } + $add .= match ($matches[1]) { + "ERROR", "SEVERE" => FORMAT_RED, + "INTERNAL", "DEBUG" => FORMAT_WHITE, + "WARNING" => FORMAT_YELLOW, + "NOTICE" => FORMAT_AQUA, + default => FORMAT_GRAY, + }; } $message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET); }else{ diff --git a/src/material/Item.php b/src/material/Item.php index 31e0dd16..13f8e350 100755 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -259,20 +259,14 @@ class Item{ //TODO remove? public function getPickaxeLevel(){ //Returns false or level of the pickaxe - switch($this->id){ - case WOODEN_PICKAXE: - return 1; - case GOLDEN_PICKAXE: - return 2; - case STONE_PICKAXE: - return 3; - case IRON_PICKAXE: - return 4; - case DIAMOND_PICKAXE: - return 5; - default: - return false; - } + return match ($this->id) { + WOODEN_PICKAXE => 1, + GOLDEN_PICKAXE => 2, + STONE_PICKAXE => 3, + IRON_PICKAXE => 4, + DIAMOND_PICKAXE => 5, + default => false, + }; } public function isAxe(){ diff --git a/src/material/block/nonfull/IronDoorBlock.php b/src/material/block/nonfull/IronDoorBlock.php index 6dda4ee5..e394b325 100644 --- a/src/material/block/nonfull/IronDoorBlock.php +++ b/src/material/block/nonfull/IronDoorBlock.php @@ -11,21 +11,15 @@ class IronDoorBlock extends DoorBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.95; - case 4: - return 1.25; - case 3: - return 1.9; - case 2: - return 0.65; - case 1: - return 3.75; - default: - return 25; } + return match ($item->getPickaxeLevel()) { + 5 => 0.95, + 4 => 1.25, + 3 => 1.9, + 2 => 0.65, + 1 => 3.75, + default => 25, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/nonfull/SlabBlock.php b/src/material/block/nonfull/SlabBlock.php index 3dae5588..89ab5e4c 100644 --- a/src/material/block/nonfull/SlabBlock.php +++ b/src/material/block/nonfull/SlabBlock.php @@ -93,21 +93,15 @@ class SlabBlock extends TransparentBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 10; } + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/nonfull/WoodSlabBlock.php b/src/material/block/nonfull/WoodSlabBlock.php index 6d7b5104..0b4a0615 100644 --- a/src/material/block/nonfull/WoodSlabBlock.php +++ b/src/material/block/nonfull/WoodSlabBlock.php @@ -89,21 +89,15 @@ class WoodSlabBlock extends TransparentBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->isAxe()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 3; } + return match ($item->isAxe()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 3, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/nonfull/stairs/WoodStairsBlock.php b/src/material/block/nonfull/stairs/WoodStairsBlock.php index 7a847e65..07463e56 100644 --- a/src/material/block/nonfull/stairs/WoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/WoodStairsBlock.php @@ -9,21 +9,15 @@ class WoodStairsBlock extends StairBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->isAxe()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 3; } + return match ($item->isAxe()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 3, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/CoalOreBlock.php b/src/material/block/ore/CoalOreBlock.php index bdf1ad29..df21d9a2 100644 --- a/src/material/block/ore/CoalOreBlock.php +++ b/src/material/block/ore/CoalOreBlock.php @@ -10,21 +10,15 @@ class CoalOreBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.6; - case 4: - return 0.75; - case 3: - return 1.15; - case 2: - return 0.4; - case 1: - return 2.25; - default: - return 15; } + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + 3 => 1.15, + 2 => 0.4, + 1 => 2.25, + default => 15, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/DiamondOreBlock.php b/src/material/block/ore/DiamondOreBlock.php index fc399807..b1ceb706 100644 --- a/src/material/block/ore/DiamondOreBlock.php +++ b/src/material/block/ore/DiamondOreBlock.php @@ -10,15 +10,12 @@ class DiamondOreBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.6; - case 4: - return 0.75; - default: - return 15; } + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + default => 15, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/GlowingRedstoneOreBlock.php b/src/material/block/ore/GlowingRedstoneOreBlock.php index 9915c10e..a75848b6 100644 --- a/src/material/block/ore/GlowingRedstoneOreBlock.php +++ b/src/material/block/ore/GlowingRedstoneOreBlock.php @@ -18,15 +18,12 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.6; - case 4: - return 0.75; - default: - return 15; } + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + default => 15, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/GoldOreBlock.php b/src/material/block/ore/GoldOreBlock.php index e715498d..45f9a49d 100644 --- a/src/material/block/ore/GoldOreBlock.php +++ b/src/material/block/ore/GoldOreBlock.php @@ -10,15 +10,12 @@ class GoldOreBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.6; - case 4: - return 0.75; - default: - return 15; } + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + default => 15, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/IronOreBlock.php b/src/material/block/ore/IronOreBlock.php index 3ad09768..33ac4c35 100644 --- a/src/material/block/ore/IronOreBlock.php +++ b/src/material/block/ore/IronOreBlock.php @@ -10,17 +10,13 @@ class IronOreBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.6; - case 4: - return 0.75; - case 3: - return 1.15; - default: - return 15; } + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + 3 => 1.15, + default => 15, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/LapisOreBlock.php b/src/material/block/ore/LapisOreBlock.php index f75f6a9d..ff7cd6c6 100644 --- a/src/material/block/ore/LapisOreBlock.php +++ b/src/material/block/ore/LapisOreBlock.php @@ -10,17 +10,13 @@ class LapisOreBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.6; - case 4: - return 0.75; - case 3: - return 1.15; - default: - return 15; } + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + 3 => 1.15, + default => 15, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/BricksBlock.php b/src/material/block/solid/BricksBlock.php index bd571961..7e83f362 100644 --- a/src/material/block/solid/BricksBlock.php +++ b/src/material/block/solid/BricksBlock.php @@ -10,21 +10,15 @@ class BricksBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 10; } + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/BurningFurnaceBlock.php b/src/material/block/solid/BurningFurnaceBlock.php index da123cd5..625a7e5a 100644 --- a/src/material/block/solid/BurningFurnaceBlock.php +++ b/src/material/block/solid/BurningFurnaceBlock.php @@ -55,21 +55,15 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.7; - case 4: - return 0.9; - case 3: - return 1.35; - case 2: - return 0.45; - case 1: - return 2.65; - default: - return 17.5; } + return match ($item->getPickaxeLevel()) { + 5 => 0.7, + 4 => 0.9, + 3 => 1.35, + 2 => 0.45, + 1 => 2.65, + default => 17.5, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/CoalBlock.php b/src/material/block/solid/CoalBlock.php index c81d36f7..4fba5e46 100644 --- a/src/material/block/solid/CoalBlock.php +++ b/src/material/block/solid/CoalBlock.php @@ -10,21 +10,15 @@ class CoalBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.95; - case 4: - return 1.25; - case 3: - return 1.9; - case 2: - return 0.65; - case 1: - return 3.75; - default: - return 25; } + return match ($item->getPickaxeLevel()) { + 5 => 0.95, + 4 => 1.25, + 3 => 1.9, + 2 => 0.65, + 1 => 3.75, + default => 25, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/CobblestoneBlock.php b/src/material/block/solid/CobblestoneBlock.php index f6c60a4e..23e51283 100644 --- a/src/material/block/solid/CobblestoneBlock.php +++ b/src/material/block/solid/CobblestoneBlock.php @@ -10,21 +10,15 @@ class CobblestoneBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 10; } + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/DiamondBlock.php b/src/material/block/solid/DiamondBlock.php index 308860e6..f0e7efde 100644 --- a/src/material/block/solid/DiamondBlock.php +++ b/src/material/block/solid/DiamondBlock.php @@ -10,15 +10,12 @@ class DiamondBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.95; - case 4: - return 1.25; - default: - return 25; } + return match ($item->getPickaxeLevel()) { + 5 => 0.95, + 4 => 1.25, + default => 25, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/DoubleSlabBlock.php b/src/material/block/solid/DoubleSlabBlock.php index 9edd5916..74351687 100755 --- a/src/material/block/solid/DoubleSlabBlock.php +++ b/src/material/block/solid/DoubleSlabBlock.php @@ -21,21 +21,15 @@ class DoubleSlabBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 10; } + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/DoubleWoodSlabBlock.php b/src/material/block/solid/DoubleWoodSlabBlock.php index fffe3417..2a278272 100644 --- a/src/material/block/solid/DoubleWoodSlabBlock.php +++ b/src/material/block/solid/DoubleWoodSlabBlock.php @@ -17,21 +17,15 @@ class DoubleWoodSlabBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->isAxe()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 3; } + return match ($item->isAxe()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 3, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/GoldBlock.php b/src/material/block/solid/GoldBlock.php index 28c136c3..df7c80a7 100644 --- a/src/material/block/solid/GoldBlock.php +++ b/src/material/block/solid/GoldBlock.php @@ -10,15 +10,12 @@ class GoldBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.6; - case 4: - return 0.75; - default: - return 15; } + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + default => 15, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/IceBlock.php b/src/material/block/solid/IceBlock.php index 4cc688cf..82c2b896 100644 --- a/src/material/block/solid/IceBlock.php +++ b/src/material/block/solid/IceBlock.php @@ -57,21 +57,15 @@ class IceBlock extends TransparentBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.1; - case 4: - return 0.15; - case 3: - return 0.2; - case 2: - return 0.1; - case 1: - return 0.4; - default: - return 0.75; } + return match ($item->getPickaxeLevel()) { + 5 => 0.1, + 4 => 0.15, + 3 => 0.2, + 2 => 0.1, + 1 => 0.4, + default => 0.75, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/IronBlock.php b/src/material/block/solid/IronBlock.php index 12acd700..7601854e 100644 --- a/src/material/block/solid/IronBlock.php +++ b/src/material/block/solid/IronBlock.php @@ -10,17 +10,13 @@ class IronBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.95; - case 4: - return 1.25; - case 3: - return 1.9; - default: - return 25; } + return match ($item->getPickaxeLevel()) { + 5 => 0.95, + 4 => 1.25, + 3 => 1.9, + default => 25, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/LapisBlock.php b/src/material/block/solid/LapisBlock.php index 868f3077..5227b504 100644 --- a/src/material/block/solid/LapisBlock.php +++ b/src/material/block/solid/LapisBlock.php @@ -10,17 +10,13 @@ class LapisBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.6; - case 4: - return 0.75; - case 3: - return 1.15; - default: - return 15; } + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + 3 => 1.15, + default => 15, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/MossStoneBlock.php b/src/material/block/solid/MossStoneBlock.php index 20242931..8d5743a8 100644 --- a/src/material/block/solid/MossStoneBlock.php +++ b/src/material/block/solid/MossStoneBlock.php @@ -10,21 +10,15 @@ class MossStoneBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 10; } + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/NetherBricksBlock.php b/src/material/block/solid/NetherBricksBlock.php index 2b0b5b8c..0cefb228 100644 --- a/src/material/block/solid/NetherBricksBlock.php +++ b/src/material/block/solid/NetherBricksBlock.php @@ -10,21 +10,15 @@ class NetherBricksBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 10; } + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/NetherrackBlock.php b/src/material/block/solid/NetherrackBlock.php index 8ff38854..518a446d 100644 --- a/src/material/block/solid/NetherrackBlock.php +++ b/src/material/block/solid/NetherrackBlock.php @@ -10,21 +10,15 @@ class NetherrackBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.1; - case 4: - return 0.1; - case 3: - return 0.15; - case 2: - return 0.05; - case 1: - return 0.3; - default: - return 2; } + return match ($item->getPickaxeLevel()) { + 5 => 0.1, + 4 => 0.1, + 3 => 0.15, + 2 => 0.05, + 1 => 0.3, + default => 2, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/QuartzBlock.php b/src/material/block/solid/QuartzBlock.php index 5ceb6385..ed9a047f 100644 --- a/src/material/block/solid/QuartzBlock.php +++ b/src/material/block/solid/QuartzBlock.php @@ -16,21 +16,15 @@ class QuartzBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.15; - case 4: - return 0.2; - case 3: - return 0.3; - case 2: - return 0.1; - case 1: - return 0.6; - default: - return 4; } + return match ($item->getPickaxeLevel()) { + 5 => 0.15, + 4 => 0.2, + 3 => 0.3, + 2 => 0.1, + 1 => 0.6, + default => 4, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/SandstoneBlock.php b/src/material/block/solid/SandstoneBlock.php index 2d800596..4d681022 100644 --- a/src/material/block/solid/SandstoneBlock.php +++ b/src/material/block/solid/SandstoneBlock.php @@ -16,21 +16,15 @@ class SandstoneBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.15; - case 4: - return 0.2; - case 3: - return 0.3; - case 2: - return 0.1; - case 1: - return 0.6; - default: - return 4; } + return match ($item->getPickaxeLevel()) { + 5 => 0.15, + 4 => 0.2, + 3 => 0.3, + 2 => 0.1, + 1 => 0.6, + default => 4, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/StoneBlock.php b/src/material/block/solid/StoneBlock.php index ac838511..562d3d1c 100644 --- a/src/material/block/solid/StoneBlock.php +++ b/src/material/block/solid/StoneBlock.php @@ -10,21 +10,15 @@ class StoneBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 7.5; } + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 7.5, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/StoneBricksBlock.php b/src/material/block/solid/StoneBricksBlock.php index 0ad41942..429c7fd1 100644 --- a/src/material/block/solid/StoneBricksBlock.php +++ b/src/material/block/solid/StoneBricksBlock.php @@ -17,21 +17,15 @@ class StoneBricksBlock extends SolidBlock{ public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; - } - switch($item->getPickaxeLevel()){ - case 5: - return 0.4; - case 4: - return 0.5; - case 3: - return 0.75; - case 2: - return 0.25; - case 1: - return 1.5; - default: - return 7.5; } + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 7.5, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/item/base/ItemAxe.php b/src/material/item/base/ItemAxe.php index 6bbc3060..4c3d140f 100644 --- a/src/material/item/base/ItemAxe.php +++ b/src/material/item/base/ItemAxe.php @@ -7,20 +7,14 @@ abstract class ItemAxe extends ItemTool } public function getLevel(){ - switch($this->id){ - case WOODEN_AXE: - return 1; - case GOLDEN_AXE: - return 2; - case STONE_AXE: - return 3; - case IRON_AXE: - return 4; - case DIAMOND_AXE: - return 5; - default: - return false; - } + return match ($this->id) { + WOODEN_AXE => 1, + GOLDEN_AXE => 2, + STONE_AXE => 3, + IRON_AXE => 4, + DIAMOND_AXE => 5, + default => false, + }; } } diff --git a/src/material/item/base/ItemHoe.php b/src/material/item/base/ItemHoe.php index b239b9cf..56bccf02 100644 --- a/src/material/item/base/ItemHoe.php +++ b/src/material/item/base/ItemHoe.php @@ -16,20 +16,14 @@ abstract class ItemHoe extends ItemTool } public function getLevel(){ - switch($this->id){ - case WOODEN_HOE: - return 1; - case GOLDEN_HOE: - return 2; - case STONE_HOE: - return 3; - case IRON_HOE: - return 4; - case DIAMOND_HOE: - return 5; - default: - return false; - } + return match ($this->id) { + WOODEN_HOE => 1, + GOLDEN_HOE => 2, + STONE_HOE => 3, + IRON_HOE => 4, + DIAMOND_HOE => 5, + default => false, + }; } } diff --git a/src/material/item/base/ItemPickaxe.php b/src/material/item/base/ItemPickaxe.php index f39ce675..e2b0928b 100644 --- a/src/material/item/base/ItemPickaxe.php +++ b/src/material/item/base/ItemPickaxe.php @@ -12,20 +12,14 @@ abstract class ItemPickaxe extends ItemTool } public function getLevel(){ - switch($this->id){ - case WOODEN_PICKAXE: - return 1; - case GOLDEN_PICKAXE: - return 2; - case STONE_PICKAXE: - return 3; - case IRON_PICKAXE: - return 4; - case DIAMOND_PICKAXE: - return 5; - default: - return false; - } + return match ($this->id) { + WOODEN_PICKAXE => 1, + GOLDEN_PICKAXE => 2, + STONE_PICKAXE => 3, + IRON_PICKAXE => 4, + DIAMOND_PICKAXE => 5, + default => false, + }; } } diff --git a/src/material/item/base/ItemShovel.php b/src/material/item/base/ItemShovel.php index 08c20b8f..c8ac6e9c 100644 --- a/src/material/item/base/ItemShovel.php +++ b/src/material/item/base/ItemShovel.php @@ -7,20 +7,14 @@ class ItemShovel extends ItemTool } public function getLevel(){ - switch($this->id){ - case WOODEN_SHOVEL: - return 1; - case GOLDEN_SHOVEL: - return 2; - case STONE_SHOVEL: - return 3; - case IRON_SHOVEL: - return 4; - case DIAMOND_SHOVEL: - return 5; - default: - return false; - } + return match ($this->id) { + WOODEN_SHOVEL => 1, + GOLDEN_SHOVEL => 2, + STONE_SHOVEL => 3, + IRON_SHOVEL => 4, + DIAMOND_SHOVEL => 5, + default => false, + }; } } diff --git a/src/material/item/base/ItemSword.php b/src/material/item/base/ItemSword.php index 37f54b4d..ccfb5393 100644 --- a/src/material/item/base/ItemSword.php +++ b/src/material/item/base/ItemSword.php @@ -8,20 +8,14 @@ abstract class ItemSword extends ItemTool } public function getLevel(){ - switch($this->id){ - case WOODEN_SWORD: - return 1; - case GOLDEN_SWORD: - return 2; - case STONE_SWORD: - return 3; - case IRON_SWORD: - return 4; - case DIAMOND_SWORD: - return 5; - default: - return false; - } + return match ($this->id) { + WOODEN_SWORD => 1, + GOLDEN_SWORD => 2, + STONE_SWORD => 3, + IRON_SWORD => 4, + DIAMOND_SWORD => 5, + default => false, + }; } } diff --git a/src/math/Matrix.php b/src/math/Matrix.php index 2684dbea..e88f26fe 100644 --- a/src/math/Matrix.php +++ b/src/math/Matrix.php @@ -140,16 +140,13 @@ class Matrix implements ArrayAccess{ if($this->isSquare() !== true){ return false; } - switch($this->rows){ - case 1: - return 0; - case 2: - return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0]; - case 3: - return $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1]; - } - return false; - } + return match ($this->rows) { + 1 => 0, + 2 => $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0], + 3 => $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1], + default => false, + }; + } //Computation of the determinant of 2x2 and 3x3 matrices diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 6eac681c..5d670618 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -104,22 +104,15 @@ class Vector3{ } public function getSide($side, $step = 1){ - switch((int) $side){ - case 0: - return new Vector3($this->x, $this->y - $step, $this->z); - case 1: - return new Vector3($this->x, $this->y + $step, $this->z); - case 2: - return new Vector3($this->x, $this->y, $this->z - $step); - case 3: - return new Vector3($this->x, $this->y, $this->z + $step); - case 4: - return new Vector3($this->x - $step, $this->y, $this->z); - case 5: - return new Vector3($this->x + $step, $this->y, $this->z); - default: - return $this; - } + return match ((int)$side) { + 0 => new Vector3($this->x, $this->y - $step, $this->z), + 1 => new Vector3($this->x, $this->y + $step, $this->z), + 2 => new Vector3($this->x, $this->y, $this->z - $step), + 3 => new Vector3($this->x, $this->y, $this->z + $step), + 4 => new Vector3($this->x - $step, $this->y, $this->z), + 5 => new Vector3($this->x + $step, $this->y, $this->z), + default => $this, + }; } public function distance($x = 0, $y = 0, $z = 0){ diff --git a/src/network/raknet/RakNetInfo.php b/src/network/raknet/RakNetInfo.php index 0093a4ce..99fd2d73 100644 --- a/src/network/raknet/RakNetInfo.php +++ b/src/network/raknet/RakNetInfo.php @@ -38,37 +38,9 @@ abstract class RakNetInfo{ const ACK = 0xc0; public static function isValid($pid){ - switch((int) $pid){ - case RakNetInfo::UNCONNECTED_PING: - case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS: - case RakNetInfo::OPEN_CONNECTION_REQUEST_1: - case RakNetInfo::OPEN_CONNECTION_REPLY_1: - case RakNetInfo::OPEN_CONNECTION_REQUEST_2: - case RakNetInfo::OPEN_CONNECTION_REPLY_2: - case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION: - case RakNetInfo::UNCONNECTED_PONG: - case RakNetInfo::ADVERTISE_SYSTEM: - case RakNetInfo::DATA_PACKET_0: - case RakNetInfo::DATA_PACKET_1: - case RakNetInfo::DATA_PACKET_2: - case RakNetInfo::DATA_PACKET_3: - case RakNetInfo::DATA_PACKET_4: - case RakNetInfo::DATA_PACKET_5: - case RakNetInfo::DATA_PACKET_6: - case RakNetInfo::DATA_PACKET_7: - case RakNetInfo::DATA_PACKET_8: - case RakNetInfo::DATA_PACKET_9: - case RakNetInfo::DATA_PACKET_A: - case RakNetInfo::DATA_PACKET_B: - case RakNetInfo::DATA_PACKET_C: - case RakNetInfo::DATA_PACKET_D: - case RakNetInfo::DATA_PACKET_E: - case RakNetInfo::DATA_PACKET_F: - case RakNetInfo::NACK: - case RakNetInfo::ACK: - return true; - default: - return false; - } + return match ((int)$pid) { + RakNetInfo::UNCONNECTED_PING, RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS, RakNetInfo::OPEN_CONNECTION_REQUEST_1, RakNetInfo::OPEN_CONNECTION_REPLY_1, RakNetInfo::OPEN_CONNECTION_REQUEST_2, RakNetInfo::OPEN_CONNECTION_REPLY_2, RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION, RakNetInfo::UNCONNECTED_PONG, RakNetInfo::ADVERTISE_SYSTEM, RakNetInfo::DATA_PACKET_0, RakNetInfo::DATA_PACKET_1, RakNetInfo::DATA_PACKET_2, RakNetInfo::DATA_PACKET_3, RakNetInfo::DATA_PACKET_4, RakNetInfo::DATA_PACKET_5, RakNetInfo::DATA_PACKET_6, RakNetInfo::DATA_PACKET_7, RakNetInfo::DATA_PACKET_8, RakNetInfo::DATA_PACKET_9, RakNetInfo::DATA_PACKET_A, RakNetInfo::DATA_PACKET_B, RakNetInfo::DATA_PACKET_C, RakNetInfo::DATA_PACKET_D, RakNetInfo::DATA_PACKET_E, RakNetInfo::DATA_PACKET_F, RakNetInfo::NACK, RakNetInfo::ACK => true, + default => false, + }; } } \ No newline at end of file diff --git a/src/utils/Utils.php b/src/utils/Utils.php index bd418cc2..705eeda3 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -14,30 +14,13 @@ class Utils{ }*/ const emojiRegex = "([*#0-9](?>\\xEF\\xB8\\x8F)?\\xE2\\x83\\xA3|\\xC2[\\xA9\\xAE]|\\xE2..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?(?>\\xEF\\xB8\\x8F)?|\\xE3(?>\\x80[\\xB0\\xBD]|\\x8A[\\x97\\x99])(?>\\xEF\\xB8\\x8F)?|\\xF0\\x9F(?>[\\x80-\\x86].(?>\\xEF\\xB8\\x8F)?|\\x87.\\xF0\\x9F\\x87.|..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?|(((?\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k\\xF0\\x9F..(\k\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))"; public static function getEntityTypeByID($id){ - switch($id){ - case 10: - case 11: - case 12: - case 13: - case 32: - case 33: - case 34: - case 35: - case 36: - return ENTITY_MOB; - case 62: - case 65: - case 80: - case 81: - case 82: - case 83: - case 84: - return ENTITY_OBJECT; - case 66: - return FALLING_SAND; - } - return $id; - } + return match ($id) { + 10, 11, 12, 13, 32, 33, 34, 35, 36 => ENTITY_MOB, + 62, 65, 80, 81, 82, 83, 84 => ENTITY_OBJECT, + 66 => FALLING_SAND, + default => $id, + }; + } public static function wrapAngleTo360($angle) { From ed4f820ff328f3f1d1dfdf8d6cdc5c3c0ed26ffd Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 17 Aug 2024 16:10:23 +0300 Subject: [PATCH 10/12] readded return in reset spawn pos & some fixes to formatting --- src/API/PluginAPI.php | 4 ++-- src/Player.php | 7 ++++--- src/entity/Entity.php | 2 +- src/entity/animal/Chicken.php | 4 ++-- src/entity/object/Arrow.php | 4 ++-- src/functions.php | 18 +++++++++--------- src/material/block/StairBlock.php | 4 ++-- src/material/block/solid/GrassBlock.php | 4 ++-- src/utils/Utils.php | 2 +- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index a9eb0158..5e98b6ce 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -55,8 +55,8 @@ class PluginAPI extends stdClass{ return; } foreach($this->plugins as $p){ - if(method_exists($p[0], "__destruct")){$p[0]->__destruct();} - } + if(method_exists($p[0], "__destruct")) $p[0]->__destruct(); + } unset($this->plugins); } diff --git a/src/Player.php b/src/Player.php index 6743ac42..7ffc2077 100755 --- a/src/Player.php +++ b/src/Player.php @@ -413,7 +413,7 @@ class Player{ * @return Item */ public function getSlot($slot){ - return $this->inventory[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); + return $this->inventory[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); } /** @@ -720,7 +720,7 @@ class Player{ * @return Item */ public function getArmor($slot){ - return $this->armor[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); + return $this->armor[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0); } public function setArmor($slot, Item $armor, $send = true){ @@ -1029,7 +1029,8 @@ class Player{ } } } - reset_spawn_pos: + return; + reset_spawn_pos: $this->spawnPosition = $this->server->api->level->getDefault()->getSpawn(); } } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 7c4a05e0..e3d70fa1 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1496,7 +1496,7 @@ class Entity extends Position { if($this->class === ENTITY_PLAYER){ $this->player->teleport(new Vector3($this->x, $this->y, $this->z), false, false, true, false); - } + } } public function moveEntityWithOffset($oX, $oY, $oZ) diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index f4e7e266..2b19cd1a 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -36,8 +36,8 @@ class Chicken extends Animal{ } public function fall(){} //chickens have no fall dmg? - - public function dropAnEgg(){ + + public function dropAnEgg(){ if($this->closed){ return; } diff --git a/src/entity/object/Arrow.php b/src/entity/object/Arrow.php index 1b84c920..693b6377 100644 --- a/src/entity/object/Arrow.php +++ b/src/entity/object/Arrow.php @@ -139,7 +139,7 @@ class Arrow extends Entity{ ++$this->groundTicks; if($this->groundTicks >= 1200){ //TODO customizeable? $this->close(); - } + } }else{ $this->inGround = false; $this->speedX *= lcg_value() * 0.2; @@ -277,4 +277,4 @@ class Arrow extends Entity{ $player->dataPacket($pk); } } -} \ No newline at end of file +} diff --git a/src/functions.php b/src/functions.php index 4717289a..a3e6e3bf 100644 --- a/src/functions.php +++ b/src/functions.php @@ -118,7 +118,7 @@ function arg($name, $default = false){ $arguments = arguments($argv); } - return $arguments["commands"][$name] ?? $default; + return $arguments["commands"][$name] ?? $default; } function arguments($args){ @@ -159,7 +159,7 @@ function arguments($args){ $ret['input'][] = $arg; - } + } return $ret; } @@ -175,13 +175,13 @@ function console($message, $EOL = true, $log = true, $level = 1){ if(ENABLE_ANSI === true){ $add = ""; if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){ - $add .= match ($matches[1]) { - "ERROR", "SEVERE" => FORMAT_RED, - "INTERNAL", "DEBUG" => FORMAT_WHITE, - "WARNING" => FORMAT_YELLOW, - "NOTICE" => FORMAT_AQUA, - default => FORMAT_GRAY, - }; + $add .= match ($matches[1]) { + "ERROR", "SEVERE" => FORMAT_RED, + "INTERNAL", "DEBUG" => FORMAT_WHITE, + "WARNING" => FORMAT_YELLOW, + "NOTICE" => FORMAT_AQUA, + default => FORMAT_GRAY, + }; } $message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET); }else{ diff --git a/src/material/block/StairBlock.php b/src/material/block/StairBlock.php index 4a29e2a4..9af56b50 100644 --- a/src/material/block/StairBlock.php +++ b/src/material/block/StairBlock.php @@ -80,7 +80,7 @@ class StairBlock extends TransparentBlock{ for($v15 = 0; $v15 < /*count($v11}*/ 2; ++$v15){ $v16 = $v11[$v15]; if($v16 == $v12){ - //wat + //wat } } @@ -360,4 +360,4 @@ class StairBlock extends TransparentBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/GrassBlock.php b/src/material/block/solid/GrassBlock.php index 66d4ddbe..c258af29 100644 --- a/src/material/block/solid/GrassBlock.php +++ b/src/material/block/solid/GrassBlock.php @@ -45,7 +45,7 @@ class GrassBlock extends SolidBlock{ ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(295,0,1)); return; } - } + } public static function onRandomTick(Level $level, $x, $y, $z){ if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z)) && mt_rand(0, 2) == 1){ $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0); @@ -64,4 +64,4 @@ class GrassBlock extends SolidBlock{ } } -} \ No newline at end of file +} diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 705eeda3..c2cfb754 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -564,7 +564,7 @@ class Utils{ } public static function readBool($b){ - return !(Utils::readByte($b, false) === 0); + return Utils::readByte($b, false) != 0; } public static function writeBool($b){ From 89eb7097a3e219c5567362551094674a3fa15a46 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 17 Aug 2024 16:21:02 +0300 Subject: [PATCH 11/12] hopefully replaced spaces with tabs everywhere --- src/API/LevelAPI.php | 10 ++++---- src/API/PlayerAPI.php | 24 +++++++++---------- src/entity/ai/tasks/TaskAttackPlayer.php | 2 +- src/material/Item.php | 16 ++++++------- src/material/block/nonfull/IronDoorBlock.php | 16 ++++++------- src/material/block/nonfull/SlabBlock.php | 18 +++++++------- src/material/block/nonfull/WoodSlabBlock.php | 18 +++++++------- .../block/nonfull/stairs/WoodStairsBlock.php | 18 +++++++------- src/material/block/ore/CoalOreBlock.php | 18 +++++++------- src/material/block/ore/DiamondOreBlock.php | 12 +++++----- .../block/ore/GlowingRedstoneOreBlock.php | 12 +++++----- src/material/block/ore/GoldOreBlock.php | 12 +++++----- src/material/block/ore/IronOreBlock.php | 14 +++++------ src/material/block/ore/LapisOreBlock.php | 14 +++++------ src/material/block/solid/BricksBlock.php | 18 +++++++------- .../block/solid/BurningFurnaceBlock.php | 18 +++++++------- src/material/block/solid/CoalBlock.php | 18 +++++++------- src/material/block/solid/CobblestoneBlock.php | 18 +++++++------- src/material/block/solid/DiamondBlock.php | 12 +++++----- src/material/block/solid/DoubleSlabBlock.php | 16 ++++++------- .../block/solid/DoubleWoodSlabBlock.php | 18 +++++++------- src/material/block/solid/GoldBlock.php | 12 +++++----- src/material/block/solid/IceBlock.php | 16 ++++++------- src/material/block/solid/IronBlock.php | 14 +++++------ src/material/block/solid/LapisBlock.php | 14 +++++------ src/material/block/solid/MossStoneBlock.php | 18 +++++++------- .../block/solid/NetherBricksBlock.php | 18 +++++++------- src/material/block/solid/NetherrackBlock.php | 18 +++++++------- src/material/block/solid/QuartzBlock.php | 18 +++++++------- src/material/block/solid/SandstoneBlock.php | 18 +++++++------- src/material/block/solid/StoneBlock.php | 18 +++++++------- src/material/block/solid/StoneBricksBlock.php | 18 +++++++------- src/material/item/base/ItemAxe.php | 16 ++++++------- src/material/item/base/ItemHoe.php | 16 ++++++------- src/material/item/base/ItemPickaxe.php | 16 ++++++------- src/material/item/base/ItemShovel.php | 16 ++++++------- src/material/item/base/ItemSword.php | 16 ++++++------- src/math/Matrix.php | 16 ++++++------- src/math/Vector3.php | 20 ++++++++-------- src/network/raknet/RakNetInfo.php | 10 ++++---- src/recipes/CraftingRecipes.php | 4 ++-- src/utils/Utils.php | 14 +++++------ 42 files changed, 324 insertions(+), 324 deletions(-) diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 380c3884..30515e7a 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -145,11 +145,11 @@ class LevelAPI{ if($generator !== false and class_exists($generator)){ $generator = new $generator($options); }else{ - $generator = match (strtoupper($this->server->api->getProperty("level-type"))) { - "FLAT" => new SuperflatGenerator($options), - "VANILLA" => new VanillaGenerator($options), - default => new TemporalGenerator($options), - }; + $generator = match (strtoupper($this->server->api->getProperty("level-type"))) { + "FLAT" => new SuperflatGenerator($options), + "VANILLA" => new VanillaGenerator($options), + default => new TemporalGenerator($options), + }; } $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed); $gen->generate(); diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index e817e90c..0e7ac1ab 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -57,18 +57,18 @@ class PlayerAPI{ } } }else{ - $message = match ($data["cause"]) { - "cactus" => " was pricked to death", - "lava" => " tried to swim in lava", - "fire" => " went up in flames", - "burning" => " burned to death", - "suffocation" => " suffocated in a wall", - "water" => " drowned", - "void" => " fell out of the world", - "fall" => " hit the ground too hard", - "explosion" => " blew up", - default => " died", - }; + $message = match ($data["cause"]) { + "cactus" => " was pricked to death", + "lava" => " tried to swim in lava", + "fire" => " went up in flames", + "burning" => " burned to death", + "suffocation" => " suffocated in a wall", + "water" => " drowned", + "void" => " fell out of the world", + "fall" => " hit the ground too hard", + "explosion" => " blew up", + default => " died", + }; } $this->server->api->chat->broadcast($data["player"]->username . $message); return true; diff --git a/src/entity/ai/tasks/TaskAttackPlayer.php b/src/entity/ai/tasks/TaskAttackPlayer.php index 7615dbf3..8760cd11 100644 --- a/src/entity/ai/tasks/TaskAttackPlayer.php +++ b/src/entity/ai/tasks/TaskAttackPlayer.php @@ -87,7 +87,7 @@ class TaskAttackPlayer extends TaskBase } public function onEnd(EntityAI $ai) - { + { $ai->entity->target = false; } diff --git a/src/material/Item.php b/src/material/Item.php index 13f8e350..49a1a80b 100755 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -259,14 +259,14 @@ class Item{ //TODO remove? public function getPickaxeLevel(){ //Returns false or level of the pickaxe - return match ($this->id) { - WOODEN_PICKAXE => 1, - GOLDEN_PICKAXE => 2, - STONE_PICKAXE => 3, - IRON_PICKAXE => 4, - DIAMOND_PICKAXE => 5, - default => false, - }; + return match ($this->id) { + WOODEN_PICKAXE => 1, + GOLDEN_PICKAXE => 2, + STONE_PICKAXE => 3, + IRON_PICKAXE => 4, + DIAMOND_PICKAXE => 5, + default => false, + }; } public function isAxe(){ diff --git a/src/material/block/nonfull/IronDoorBlock.php b/src/material/block/nonfull/IronDoorBlock.php index e394b325..5ac59aae 100644 --- a/src/material/block/nonfull/IronDoorBlock.php +++ b/src/material/block/nonfull/IronDoorBlock.php @@ -12,14 +12,14 @@ class IronDoorBlock extends DoorBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.95, - 4 => 1.25, - 3 => 1.9, - 2 => 0.65, - 1 => 3.75, - default => 25, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.95, + 4 => 1.25, + 3 => 1.9, + 2 => 0.65, + 1 => 3.75, + default => 25, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/nonfull/SlabBlock.php b/src/material/block/nonfull/SlabBlock.php index 89ab5e4c..3319bb7b 100644 --- a/src/material/block/nonfull/SlabBlock.php +++ b/src/material/block/nonfull/SlabBlock.php @@ -94,14 +94,14 @@ class SlabBlock extends TransparentBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 10, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ @@ -113,4 +113,4 @@ class SlabBlock extends TransparentBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/nonfull/WoodSlabBlock.php b/src/material/block/nonfull/WoodSlabBlock.php index 0b4a0615..d39f0931 100644 --- a/src/material/block/nonfull/WoodSlabBlock.php +++ b/src/material/block/nonfull/WoodSlabBlock.php @@ -90,14 +90,14 @@ class WoodSlabBlock extends TransparentBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->isAxe()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 3, - }; + return match ($item->isAxe()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 3, + }; } public function getDrops(Item $item, Player $player){ @@ -105,4 +105,4 @@ class WoodSlabBlock extends TransparentBlock{ array($this->id, $this->meta & 0x07, 1), ); } -} \ No newline at end of file +} diff --git a/src/material/block/nonfull/stairs/WoodStairsBlock.php b/src/material/block/nonfull/stairs/WoodStairsBlock.php index 07463e56..0421dac4 100644 --- a/src/material/block/nonfull/stairs/WoodStairsBlock.php +++ b/src/material/block/nonfull/stairs/WoodStairsBlock.php @@ -10,14 +10,14 @@ class WoodStairsBlock extends StairBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->isAxe()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 3, - }; + return match ($item->isAxe()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 3, + }; } public function getDrops(Item $item, Player $player){ @@ -25,4 +25,4 @@ class WoodStairsBlock extends StairBlock{ array($this->id, 0, 1), ); } -} \ No newline at end of file +} diff --git a/src/material/block/ore/CoalOreBlock.php b/src/material/block/ore/CoalOreBlock.php index df21d9a2..12e5c262 100644 --- a/src/material/block/ore/CoalOreBlock.php +++ b/src/material/block/ore/CoalOreBlock.php @@ -11,14 +11,14 @@ class CoalOreBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.6, - 4 => 0.75, - 3 => 1.15, - 2 => 0.4, - 1 => 2.25, - default => 15, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + 3 => 1.15, + 2 => 0.4, + 1 => 2.25, + default => 15, + }; } public function getDrops(Item $item, Player $player){ @@ -31,4 +31,4 @@ class CoalOreBlock extends SolidBlock{ } } -} \ No newline at end of file +} diff --git a/src/material/block/ore/DiamondOreBlock.php b/src/material/block/ore/DiamondOreBlock.php index b1ceb706..dec08e78 100644 --- a/src/material/block/ore/DiamondOreBlock.php +++ b/src/material/block/ore/DiamondOreBlock.php @@ -11,11 +11,11 @@ class DiamondOreBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.6, - 4 => 0.75, - default => 15, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + default => 15, + }; } public function getDrops(Item $item, Player $player){ @@ -27,4 +27,4 @@ class DiamondOreBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/ore/GlowingRedstoneOreBlock.php b/src/material/block/ore/GlowingRedstoneOreBlock.php index a75848b6..33dd8e0c 100644 --- a/src/material/block/ore/GlowingRedstoneOreBlock.php +++ b/src/material/block/ore/GlowingRedstoneOreBlock.php @@ -19,11 +19,11 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.6, - 4 => 0.75, - default => 15, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + default => 15, + }; } public function getDrops(Item $item, Player $player){ @@ -36,4 +36,4 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{ } } -} \ No newline at end of file +} diff --git a/src/material/block/ore/GoldOreBlock.php b/src/material/block/ore/GoldOreBlock.php index 45f9a49d..c835dbc1 100644 --- a/src/material/block/ore/GoldOreBlock.php +++ b/src/material/block/ore/GoldOreBlock.php @@ -11,11 +11,11 @@ class GoldOreBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.6, - 4 => 0.75, - default => 15, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + default => 15, + }; } public function getDrops(Item $item, Player $player){ @@ -27,4 +27,4 @@ class GoldOreBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/ore/IronOreBlock.php b/src/material/block/ore/IronOreBlock.php index 33ac4c35..d8d001ff 100644 --- a/src/material/block/ore/IronOreBlock.php +++ b/src/material/block/ore/IronOreBlock.php @@ -11,12 +11,12 @@ class IronOreBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.6, - 4 => 0.75, - 3 => 1.15, - default => 15, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + 3 => 1.15, + default => 15, + }; } public function getDrops(Item $item, Player $player){ @@ -28,4 +28,4 @@ class IronOreBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/ore/LapisOreBlock.php b/src/material/block/ore/LapisOreBlock.php index ff7cd6c6..ecb3e83f 100644 --- a/src/material/block/ore/LapisOreBlock.php +++ b/src/material/block/ore/LapisOreBlock.php @@ -11,12 +11,12 @@ class LapisOreBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.6, - 4 => 0.75, - 3 => 1.15, - default => 15, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + 3 => 1.15, + default => 15, + }; } public function getDrops(Item $item, Player $player){ @@ -29,4 +29,4 @@ class LapisOreBlock extends SolidBlock{ } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/BricksBlock.php b/src/material/block/solid/BricksBlock.php index 7e83f362..97f448b2 100644 --- a/src/material/block/solid/BricksBlock.php +++ b/src/material/block/solid/BricksBlock.php @@ -11,14 +11,14 @@ class BricksBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 10, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ @@ -30,4 +30,4 @@ class BricksBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/BurningFurnaceBlock.php b/src/material/block/solid/BurningFurnaceBlock.php index 625a7e5a..0adb007c 100644 --- a/src/material/block/solid/BurningFurnaceBlock.php +++ b/src/material/block/solid/BurningFurnaceBlock.php @@ -56,14 +56,14 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.7, - 4 => 0.9, - 3 => 1.35, - 2 => 0.45, - 1 => 2.65, - default => 17.5, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.7, + 4 => 0.9, + 3 => 1.35, + 2 => 0.45, + 1 => 2.65, + default => 17.5, + }; } public function getDrops(Item $item, Player $player){ @@ -82,4 +82,4 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{ } return $drops; } -} \ No newline at end of file +} diff --git a/src/material/block/solid/CoalBlock.php b/src/material/block/solid/CoalBlock.php index 4fba5e46..cf7a252e 100644 --- a/src/material/block/solid/CoalBlock.php +++ b/src/material/block/solid/CoalBlock.php @@ -11,14 +11,14 @@ class CoalBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.95, - 4 => 1.25, - 3 => 1.9, - 2 => 0.65, - 1 => 3.75, - default => 25, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.95, + 4 => 1.25, + 3 => 1.9, + 2 => 0.65, + 1 => 3.75, + default => 25, + }; } public function getDrops(Item $item, Player $player){ @@ -30,4 +30,4 @@ class CoalBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/CobblestoneBlock.php b/src/material/block/solid/CobblestoneBlock.php index 23e51283..895953d1 100644 --- a/src/material/block/solid/CobblestoneBlock.php +++ b/src/material/block/solid/CobblestoneBlock.php @@ -11,14 +11,14 @@ class CobblestoneBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 10, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ @@ -30,4 +30,4 @@ class CobblestoneBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/DiamondBlock.php b/src/material/block/solid/DiamondBlock.php index f0e7efde..2ffeed39 100644 --- a/src/material/block/solid/DiamondBlock.php +++ b/src/material/block/solid/DiamondBlock.php @@ -11,11 +11,11 @@ class DiamondBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.95, - 4 => 1.25, - default => 25, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.95, + 4 => 1.25, + default => 25, + }; } public function getDrops(Item $item, Player $player){ @@ -27,4 +27,4 @@ class DiamondBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/DoubleSlabBlock.php b/src/material/block/solid/DoubleSlabBlock.php index 74351687..4b6f28db 100755 --- a/src/material/block/solid/DoubleSlabBlock.php +++ b/src/material/block/solid/DoubleSlabBlock.php @@ -22,14 +22,14 @@ class DoubleSlabBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 10, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/DoubleWoodSlabBlock.php b/src/material/block/solid/DoubleWoodSlabBlock.php index 2a278272..7ff69ef1 100644 --- a/src/material/block/solid/DoubleWoodSlabBlock.php +++ b/src/material/block/solid/DoubleWoodSlabBlock.php @@ -18,14 +18,14 @@ class DoubleWoodSlabBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->isAxe()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 3, - }; + return match ($item->isAxe()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 3, + }; } public function getDrops(Item $item, Player $player){ @@ -34,4 +34,4 @@ class DoubleWoodSlabBlock extends SolidBlock{ ); } -} \ No newline at end of file +} diff --git a/src/material/block/solid/GoldBlock.php b/src/material/block/solid/GoldBlock.php index df7c80a7..80006170 100644 --- a/src/material/block/solid/GoldBlock.php +++ b/src/material/block/solid/GoldBlock.php @@ -11,11 +11,11 @@ class GoldBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.6, - 4 => 0.75, - default => 15, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + default => 15, + }; } public function getDrops(Item $item, Player $player){ @@ -27,4 +27,4 @@ class GoldBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/IceBlock.php b/src/material/block/solid/IceBlock.php index 82c2b896..e5e7860d 100644 --- a/src/material/block/solid/IceBlock.php +++ b/src/material/block/solid/IceBlock.php @@ -58,14 +58,14 @@ class IceBlock extends TransparentBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.1, - 4 => 0.15, - 3 => 0.2, - 2 => 0.1, - 1 => 0.4, - default => 0.75, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.1, + 4 => 0.15, + 3 => 0.2, + 2 => 0.1, + 1 => 0.4, + default => 0.75, + }; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/IronBlock.php b/src/material/block/solid/IronBlock.php index 7601854e..504b94a1 100644 --- a/src/material/block/solid/IronBlock.php +++ b/src/material/block/solid/IronBlock.php @@ -11,12 +11,12 @@ class IronBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.95, - 4 => 1.25, - 3 => 1.9, - default => 25, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.95, + 4 => 1.25, + 3 => 1.9, + default => 25, + }; } public function getDrops(Item $item, Player $player){ @@ -28,4 +28,4 @@ class IronBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/LapisBlock.php b/src/material/block/solid/LapisBlock.php index 5227b504..1d4c4dc6 100644 --- a/src/material/block/solid/LapisBlock.php +++ b/src/material/block/solid/LapisBlock.php @@ -11,12 +11,12 @@ class LapisBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.6, - 4 => 0.75, - 3 => 1.15, - default => 15, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.6, + 4 => 0.75, + 3 => 1.15, + default => 15, + }; } public function getDrops(Item $item, Player $player){ @@ -29,4 +29,4 @@ class LapisBlock extends SolidBlock{ } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/MossStoneBlock.php b/src/material/block/solid/MossStoneBlock.php index 8d5743a8..495de40d 100644 --- a/src/material/block/solid/MossStoneBlock.php +++ b/src/material/block/solid/MossStoneBlock.php @@ -11,14 +11,14 @@ class MossStoneBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 10, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ @@ -30,4 +30,4 @@ class MossStoneBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/NetherBricksBlock.php b/src/material/block/solid/NetherBricksBlock.php index 0cefb228..bf1c7947 100644 --- a/src/material/block/solid/NetherBricksBlock.php +++ b/src/material/block/solid/NetherBricksBlock.php @@ -11,14 +11,14 @@ class NetherBricksBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 10, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 10, + }; } public function getDrops(Item $item, Player $player){ @@ -30,4 +30,4 @@ class NetherBricksBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/NetherrackBlock.php b/src/material/block/solid/NetherrackBlock.php index 518a446d..4700a083 100644 --- a/src/material/block/solid/NetherrackBlock.php +++ b/src/material/block/solid/NetherrackBlock.php @@ -11,14 +11,14 @@ class NetherrackBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.1, - 4 => 0.1, - 3 => 0.15, - 2 => 0.05, - 1 => 0.3, - default => 2, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.1, + 4 => 0.1, + 3 => 0.15, + 2 => 0.05, + 1 => 0.3, + default => 2, + }; } public function getDrops(Item $item, Player $player){ @@ -30,4 +30,4 @@ class NetherrackBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/QuartzBlock.php b/src/material/block/solid/QuartzBlock.php index ed9a047f..1c7bcfb7 100644 --- a/src/material/block/solid/QuartzBlock.php +++ b/src/material/block/solid/QuartzBlock.php @@ -17,14 +17,14 @@ class QuartzBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.15, - 4 => 0.2, - 3 => 0.3, - 2 => 0.1, - 1 => 0.6, - default => 4, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.15, + 4 => 0.2, + 3 => 0.3, + 2 => 0.1, + 1 => 0.6, + default => 4, + }; } public function getDrops(Item $item, Player $player){ @@ -36,4 +36,4 @@ class QuartzBlock extends SolidBlock{ return array(); } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/SandstoneBlock.php b/src/material/block/solid/SandstoneBlock.php index 4d681022..c6533998 100644 --- a/src/material/block/solid/SandstoneBlock.php +++ b/src/material/block/solid/SandstoneBlock.php @@ -17,14 +17,14 @@ class SandstoneBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.15, - 4 => 0.2, - 3 => 0.3, - 2 => 0.1, - 1 => 0.6, - default => 4, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.15, + 4 => 0.2, + 3 => 0.3, + 2 => 0.1, + 1 => 0.6, + default => 4, + }; } public function getDrops(Item $item, Player $player){ @@ -37,4 +37,4 @@ class SandstoneBlock extends SolidBlock{ } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/StoneBlock.php b/src/material/block/solid/StoneBlock.php index 562d3d1c..51504b66 100644 --- a/src/material/block/solid/StoneBlock.php +++ b/src/material/block/solid/StoneBlock.php @@ -11,14 +11,14 @@ class StoneBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 7.5, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 7.5, + }; } public function getDrops(Item $item, Player $player){ @@ -31,4 +31,4 @@ class StoneBlock extends SolidBlock{ } } -} \ No newline at end of file +} diff --git a/src/material/block/solid/StoneBricksBlock.php b/src/material/block/solid/StoneBricksBlock.php index 429c7fd1..58299703 100644 --- a/src/material/block/solid/StoneBricksBlock.php +++ b/src/material/block/solid/StoneBricksBlock.php @@ -18,14 +18,14 @@ class StoneBricksBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0x01){ return 0.20; } - return match ($item->getPickaxeLevel()) { - 5 => 0.4, - 4 => 0.5, - 3 => 0.75, - 2 => 0.25, - 1 => 1.5, - default => 7.5, - }; + return match ($item->getPickaxeLevel()) { + 5 => 0.4, + 4 => 0.5, + 3 => 0.75, + 2 => 0.25, + 1 => 1.5, + default => 7.5, + }; } public function getDrops(Item $item, Player $player){ @@ -38,4 +38,4 @@ class StoneBricksBlock extends SolidBlock{ } } -} \ No newline at end of file +} diff --git a/src/material/item/base/ItemAxe.php b/src/material/item/base/ItemAxe.php index 4c3d140f..5efc1d5b 100644 --- a/src/material/item/base/ItemAxe.php +++ b/src/material/item/base/ItemAxe.php @@ -7,14 +7,14 @@ abstract class ItemAxe extends ItemTool } public function getLevel(){ - return match ($this->id) { - WOODEN_AXE => 1, - GOLDEN_AXE => 2, - STONE_AXE => 3, - IRON_AXE => 4, - DIAMOND_AXE => 5, - default => false, - }; + return match ($this->id) { + WOODEN_AXE => 1, + GOLDEN_AXE => 2, + STONE_AXE => 3, + IRON_AXE => 4, + DIAMOND_AXE => 5, + default => false, + }; } } diff --git a/src/material/item/base/ItemHoe.php b/src/material/item/base/ItemHoe.php index 56bccf02..277b75fb 100644 --- a/src/material/item/base/ItemHoe.php +++ b/src/material/item/base/ItemHoe.php @@ -16,14 +16,14 @@ abstract class ItemHoe extends ItemTool } public function getLevel(){ - return match ($this->id) { - WOODEN_HOE => 1, - GOLDEN_HOE => 2, - STONE_HOE => 3, - IRON_HOE => 4, - DIAMOND_HOE => 5, - default => false, - }; + return match ($this->id) { + WOODEN_HOE => 1, + GOLDEN_HOE => 2, + STONE_HOE => 3, + IRON_HOE => 4, + DIAMOND_HOE => 5, + default => false, + }; } } diff --git a/src/material/item/base/ItemPickaxe.php b/src/material/item/base/ItemPickaxe.php index e2b0928b..91666c54 100644 --- a/src/material/item/base/ItemPickaxe.php +++ b/src/material/item/base/ItemPickaxe.php @@ -12,14 +12,14 @@ abstract class ItemPickaxe extends ItemTool } public function getLevel(){ - return match ($this->id) { - WOODEN_PICKAXE => 1, - GOLDEN_PICKAXE => 2, - STONE_PICKAXE => 3, - IRON_PICKAXE => 4, - DIAMOND_PICKAXE => 5, - default => false, - }; + return match ($this->id) { + WOODEN_PICKAXE => 1, + GOLDEN_PICKAXE => 2, + STONE_PICKAXE => 3, + IRON_PICKAXE => 4, + DIAMOND_PICKAXE => 5, + default => false, + }; } } diff --git a/src/material/item/base/ItemShovel.php b/src/material/item/base/ItemShovel.php index c8ac6e9c..20b61eba 100644 --- a/src/material/item/base/ItemShovel.php +++ b/src/material/item/base/ItemShovel.php @@ -7,14 +7,14 @@ class ItemShovel extends ItemTool } public function getLevel(){ - return match ($this->id) { - WOODEN_SHOVEL => 1, - GOLDEN_SHOVEL => 2, - STONE_SHOVEL => 3, - IRON_SHOVEL => 4, - DIAMOND_SHOVEL => 5, - default => false, - }; + return match ($this->id) { + WOODEN_SHOVEL => 1, + GOLDEN_SHOVEL => 2, + STONE_SHOVEL => 3, + IRON_SHOVEL => 4, + DIAMOND_SHOVEL => 5, + default => false, + }; } } diff --git a/src/material/item/base/ItemSword.php b/src/material/item/base/ItemSword.php index ccfb5393..6bd725e0 100644 --- a/src/material/item/base/ItemSword.php +++ b/src/material/item/base/ItemSword.php @@ -8,14 +8,14 @@ abstract class ItemSword extends ItemTool } public function getLevel(){ - return match ($this->id) { - WOODEN_SWORD => 1, - GOLDEN_SWORD => 2, - STONE_SWORD => 3, - IRON_SWORD => 4, - DIAMOND_SWORD => 5, - default => false, - }; + return match ($this->id) { + WOODEN_SWORD => 1, + GOLDEN_SWORD => 2, + STONE_SWORD => 3, + IRON_SWORD => 4, + DIAMOND_SWORD => 5, + default => false, + }; } } diff --git a/src/math/Matrix.php b/src/math/Matrix.php index e88f26fe..d2f3b245 100644 --- a/src/math/Matrix.php +++ b/src/math/Matrix.php @@ -140,13 +140,13 @@ class Matrix implements ArrayAccess{ if($this->isSquare() !== true){ return false; } - return match ($this->rows) { - 1 => 0, - 2 => $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0], - 3 => $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1], - default => false, - }; - } + return match ($this->rows) { + 1 => 0, + 2 => $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0], + 3 => $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1], + default => false, + }; + } //Computation of the determinant of 2x2 and 3x3 matrices @@ -163,4 +163,4 @@ class Matrix implements ArrayAccess{ return "Matrix({$this->rows}x{$this->columns};" . substr($s, 0, -1) . ")"; } -} \ No newline at end of file +} diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 5d670618..03dcb015 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -104,15 +104,15 @@ class Vector3{ } public function getSide($side, $step = 1){ - return match ((int)$side) { - 0 => new Vector3($this->x, $this->y - $step, $this->z), - 1 => new Vector3($this->x, $this->y + $step, $this->z), - 2 => new Vector3($this->x, $this->y, $this->z - $step), - 3 => new Vector3($this->x, $this->y, $this->z + $step), - 4 => new Vector3($this->x - $step, $this->y, $this->z), - 5 => new Vector3($this->x + $step, $this->y, $this->z), - default => $this, - }; + return match ((int)$side) { + 0 => new Vector3($this->x, $this->y - $step, $this->z), + 1 => new Vector3($this->x, $this->y + $step, $this->z), + 2 => new Vector3($this->x, $this->y, $this->z - $step), + 3 => new Vector3($this->x, $this->y, $this->z + $step), + 4 => new Vector3($this->x - $step, $this->y, $this->z), + 5 => new Vector3($this->x + $step, $this->y, $this->z), + default => $this, + }; } public function distance($x = 0, $y = 0, $z = 0){ @@ -270,4 +270,4 @@ class Vector3{ public function getIntermediateWithZValue(Vector3 $v, $y){ return $this->clipZ($v, $y); } -} \ No newline at end of file +} diff --git a/src/network/raknet/RakNetInfo.php b/src/network/raknet/RakNetInfo.php index 99fd2d73..634e2e76 100644 --- a/src/network/raknet/RakNetInfo.php +++ b/src/network/raknet/RakNetInfo.php @@ -38,9 +38,9 @@ abstract class RakNetInfo{ const ACK = 0xc0; public static function isValid($pid){ - return match ((int)$pid) { - RakNetInfo::UNCONNECTED_PING, RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS, RakNetInfo::OPEN_CONNECTION_REQUEST_1, RakNetInfo::OPEN_CONNECTION_REPLY_1, RakNetInfo::OPEN_CONNECTION_REQUEST_2, RakNetInfo::OPEN_CONNECTION_REPLY_2, RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION, RakNetInfo::UNCONNECTED_PONG, RakNetInfo::ADVERTISE_SYSTEM, RakNetInfo::DATA_PACKET_0, RakNetInfo::DATA_PACKET_1, RakNetInfo::DATA_PACKET_2, RakNetInfo::DATA_PACKET_3, RakNetInfo::DATA_PACKET_4, RakNetInfo::DATA_PACKET_5, RakNetInfo::DATA_PACKET_6, RakNetInfo::DATA_PACKET_7, RakNetInfo::DATA_PACKET_8, RakNetInfo::DATA_PACKET_9, RakNetInfo::DATA_PACKET_A, RakNetInfo::DATA_PACKET_B, RakNetInfo::DATA_PACKET_C, RakNetInfo::DATA_PACKET_D, RakNetInfo::DATA_PACKET_E, RakNetInfo::DATA_PACKET_F, RakNetInfo::NACK, RakNetInfo::ACK => true, - default => false, - }; + return match ((int)$pid) { + RakNetInfo::UNCONNECTED_PING, RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS, RakNetInfo::OPEN_CONNECTION_REQUEST_1, RakNetInfo::OPEN_CONNECTION_REPLY_1, RakNetInfo::OPEN_CONNECTION_REQUEST_2, RakNetInfo::OPEN_CONNECTION_REPLY_2, RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION, RakNetInfo::UNCONNECTED_PONG, RakNetInfo::ADVERTISE_SYSTEM, RakNetInfo::DATA_PACKET_0, RakNetInfo::DATA_PACKET_1, RakNetInfo::DATA_PACKET_2, RakNetInfo::DATA_PACKET_3, RakNetInfo::DATA_PACKET_4, RakNetInfo::DATA_PACKET_5, RakNetInfo::DATA_PACKET_6, RakNetInfo::DATA_PACKET_7, RakNetInfo::DATA_PACKET_8, RakNetInfo::DATA_PACKET_9, RakNetInfo::DATA_PACKET_A, RakNetInfo::DATA_PACKET_B, RakNetInfo::DATA_PACKET_C, RakNetInfo::DATA_PACKET_D, RakNetInfo::DATA_PACKET_E, RakNetInfo::DATA_PACKET_F, RakNetInfo::NACK, RakNetInfo::ACK => true, + default => false, + }; } -} \ No newline at end of file +} diff --git a/src/recipes/CraftingRecipes.php b/src/recipes/CraftingRecipes.php index 2db3ef96..204fb77d 100644 --- a/src/recipes/CraftingRecipes.php +++ b/src/recipes/CraftingRecipes.php @@ -3,7 +3,7 @@ class CraftingRecipes{ private static $small = [ // Probably means craftable on crafting bench and in inventory. Name it better! - // Building + // Building "CLAY:?x4=>CLAY_BLOCK:0x1", "WOODEN_PLANKS:?x4=>WORKBENCH:0x1", "GLOWSTONE_DUST:?x4=>GLOWSTONE_BLOCK:0x1", @@ -73,7 +73,7 @@ class CraftingRecipes{ ]; private static $big = [ // Probably means only craftable on crafting bench. Name it better! - // Building + // Building "WOOL:?x3,WOODEN_PLANKS:?x3=>BED:0x1", "WOODEN_PLANKS:?x8=>CHEST:0x1", "STICK:?x6=>FENCE:0x2", diff --git a/src/utils/Utils.php b/src/utils/Utils.php index c2cfb754..a6f8a08c 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -14,13 +14,13 @@ class Utils{ }*/ const emojiRegex = "([*#0-9](?>\\xEF\\xB8\\x8F)?\\xE2\\x83\\xA3|\\xC2[\\xA9\\xAE]|\\xE2..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?(?>\\xEF\\xB8\\x8F)?|\\xE3(?>\\x80[\\xB0\\xBD]|\\x8A[\\x97\\x99])(?>\\xEF\\xB8\\x8F)?|\\xF0\\x9F(?>[\\x80-\\x86].(?>\\xEF\\xB8\\x8F)?|\\x87.\\xF0\\x9F\\x87.|..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?|(((?\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k\\xF0\\x9F..(\k\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))"; public static function getEntityTypeByID($id){ - return match ($id) { - 10, 11, 12, 13, 32, 33, 34, 35, 36 => ENTITY_MOB, - 62, 65, 80, 81, 82, 83, 84 => ENTITY_OBJECT, - 66 => FALLING_SAND, - default => $id, - }; - } + return match ($id) { + 10, 11, 12, 13, 32, 33, 34, 35, 36 => ENTITY_MOB, + 62, 65, 80, 81, 82, 83, 84 => ENTITY_OBJECT, + 66 => FALLING_SAND, + default => $id, + }; + } public static function wrapAngleTo360($angle) { From 8ed1285770439683f88cafcd609173bf9ae88327 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 17 Aug 2024 16:23:24 +0300 Subject: [PATCH 12/12] readded 1 removed isset --- src/world/Level.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/Level.php b/src/world/Level.php index efc7078d..17d0cb26 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][$k])){ + if(isset($this->entityListPositioned[$index]) && isset($this->entityListPositioned[$index][$k])){ unset($this->entityListPositioned[$index][$k]); }