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