PHP8: use match function

This commit is contained in:
Sunch 2024-08-17 20:12:37 +08:00
parent 1275a4558c
commit f74e6e0638
41 changed files with 300 additions and 574 deletions

View file

@ -145,17 +145,11 @@ class LevelAPI{
if($generator !== false and class_exists($generator)){ if($generator !== false and class_exists($generator)){
$generator = new $generator($options); $generator = new $generator($options);
}else{ }else{
switch(strtoupper($this->server->api->getProperty("level-type"))){ $generator = match (strtoupper($this->server->api->getProperty("level-type"))) {
case "FLAT": "FLAT" => new SuperflatGenerator($options),
$generator = new SuperflatGenerator($options); "VANILLA" => new VanillaGenerator($options),
break; default => new TemporalGenerator($options),
case "VANILLA": };
$generator = new VanillaGenerator($options);
break;
default:
$generator = new TemporalGenerator($options);
break;
}
} }
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed); $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);
$gen->generate(); $gen->generate();

View file

@ -57,38 +57,18 @@ class PlayerAPI{
} }
} }
}else{ }else{
switch($data["cause"]){ $message = match ($data["cause"]) {
case "cactus": "cactus" => " was pricked to death",
$message = " was pricked to death"; "lava" => " tried to swim in lava",
break; "fire" => " went up in flames",
case "lava": "burning" => " burned to death",
$message = " tried to swim in lava"; "suffocation" => " suffocated in a wall",
break; "water" => " drowned",
case "fire": "void" => " fell out of the world",
$message = " went up in flames"; "fall" => " hit the ground too hard",
break; "explosion" => " blew up",
case "burning": default => " died",
$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;
}
} }
$this->server->api->chat->broadcast($data["player"]->username . $message); $this->server->api->chat->broadcast($data["player"]->username . $message);
return true; return true;

View file

@ -175,25 +175,13 @@ function console($message, $EOL = true, $log = true, $level = 1){
if(ENABLE_ANSI === true){ if(ENABLE_ANSI === true){
$add = ""; $add = "";
if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){ if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){
switch($matches[1]){ $add .= match ($matches[1]) {
case "ERROR": "ERROR", "SEVERE" => FORMAT_RED,
case "SEVERE": "INTERNAL", "DEBUG" => FORMAT_WHITE,
$add .= FORMAT_RED; "WARNING" => FORMAT_YELLOW,
break; "NOTICE" => FORMAT_AQUA,
case "INTERNAL": default => FORMAT_GRAY,
case "DEBUG": };
$add .= FORMAT_WHITE;
break;
case "WARNING":
$add .= FORMAT_YELLOW;
break;
case "NOTICE":
$add .= FORMAT_AQUA;
break;
default:
$add .= FORMAT_GRAY;
break;
}
} }
$message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET); $message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET);
}else{ }else{

View file

@ -259,20 +259,14 @@ class Item{
//TODO remove? //TODO remove?
public function getPickaxeLevel(){ //Returns false or level of the pickaxe public function getPickaxeLevel(){ //Returns false or level of the pickaxe
switch($this->id){ return match ($this->id) {
case WOODEN_PICKAXE: WOODEN_PICKAXE => 1,
return 1; GOLDEN_PICKAXE => 2,
case GOLDEN_PICKAXE: STONE_PICKAXE => 3,
return 2; IRON_PICKAXE => 4,
case STONE_PICKAXE: DIAMOND_PICKAXE => 5,
return 3; default => false,
case IRON_PICKAXE: };
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
} }
public function isAxe(){ public function isAxe(){

View file

@ -11,21 +11,15 @@ class IronDoorBlock extends DoorBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -93,21 +93,15 @@ class SlabBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -89,21 +89,15 @@ class WoodSlabBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -9,21 +9,15 @@ class WoodStairsBlock extends StairBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class CoalOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,15 +10,12 @@ class DiamondOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -18,15 +18,12 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,15 +10,12 @@ class GoldOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class IronOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class LapisOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class BricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -55,21 +55,15 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class CoalBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class CobblestoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,15 +10,12 @@ class DiamondBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -21,21 +21,15 @@ class DoubleSlabBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -17,21 +17,15 @@ class DoubleWoodSlabBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,15 +10,12 @@ class GoldBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -57,21 +57,15 @@ class IceBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class IronBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class LapisBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class MossStoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class NetherBricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class NetherrackBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -16,21 +16,15 @@ class QuartzBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -16,21 +16,15 @@ class SandstoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -10,21 +10,15 @@ class StoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -17,21 +17,15 @@ class StoneBricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; 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){ public function getDrops(Item $item, Player $player){

View file

@ -7,20 +7,14 @@ abstract class ItemAxe extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_AXE: WOODEN_AXE => 1,
return 1; GOLDEN_AXE => 2,
case GOLDEN_AXE: STONE_AXE => 3,
return 2; IRON_AXE => 4,
case STONE_AXE: DIAMOND_AXE => 5,
return 3; default => false,
case IRON_AXE: };
return 4;
case DIAMOND_AXE:
return 5;
default:
return false;
}
} }
} }

View file

@ -16,20 +16,14 @@ abstract class ItemHoe extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_HOE: WOODEN_HOE => 1,
return 1; GOLDEN_HOE => 2,
case GOLDEN_HOE: STONE_HOE => 3,
return 2; IRON_HOE => 4,
case STONE_HOE: DIAMOND_HOE => 5,
return 3; default => false,
case IRON_HOE: };
return 4;
case DIAMOND_HOE:
return 5;
default:
return false;
}
} }
} }

View file

@ -12,20 +12,14 @@ abstract class ItemPickaxe extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_PICKAXE: WOODEN_PICKAXE => 1,
return 1; GOLDEN_PICKAXE => 2,
case GOLDEN_PICKAXE: STONE_PICKAXE => 3,
return 2; IRON_PICKAXE => 4,
case STONE_PICKAXE: DIAMOND_PICKAXE => 5,
return 3; default => false,
case IRON_PICKAXE: };
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
} }
} }

View file

@ -7,20 +7,14 @@ class ItemShovel extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_SHOVEL: WOODEN_SHOVEL => 1,
return 1; GOLDEN_SHOVEL => 2,
case GOLDEN_SHOVEL: STONE_SHOVEL => 3,
return 2; IRON_SHOVEL => 4,
case STONE_SHOVEL: DIAMOND_SHOVEL => 5,
return 3; default => false,
case IRON_SHOVEL: };
return 4;
case DIAMOND_SHOVEL:
return 5;
default:
return false;
}
} }
} }

View file

@ -8,20 +8,14 @@ abstract class ItemSword extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_SWORD: WOODEN_SWORD => 1,
return 1; GOLDEN_SWORD => 2,
case GOLDEN_SWORD: STONE_SWORD => 3,
return 2; IRON_SWORD => 4,
case STONE_SWORD: DIAMOND_SWORD => 5,
return 3; default => false,
case IRON_SWORD: };
return 4;
case DIAMOND_SWORD:
return 5;
default:
return false;
}
} }
} }

View file

@ -140,16 +140,13 @@ class Matrix implements ArrayAccess{
if($this->isSquare() !== true){ if($this->isSquare() !== true){
return false; return false;
} }
switch($this->rows){ return match ($this->rows) {
case 1: 1 => 0,
return 0; 2 => $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0],
case 2: 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],
return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0]; default => false,
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;
}
//Computation of the determinant of 2x2 and 3x3 matrices //Computation of the determinant of 2x2 and 3x3 matrices

View file

@ -104,22 +104,15 @@ class Vector3{
} }
public function getSide($side, $step = 1){ public function getSide($side, $step = 1){
switch((int) $side){ return match ((int)$side) {
case 0: 0 => new Vector3($this->x, $this->y - $step, $this->z),
return new Vector3($this->x, $this->y - $step, $this->z); 1 => new Vector3($this->x, $this->y + $step, $this->z),
case 1: 2 => new Vector3($this->x, $this->y, $this->z - $step),
return new Vector3($this->x, $this->y + $step, $this->z); 3 => new Vector3($this->x, $this->y, $this->z + $step),
case 2: 4 => new Vector3($this->x - $step, $this->y, $this->z),
return new Vector3($this->x, $this->y, $this->z - $step); 5 => new Vector3($this->x + $step, $this->y, $this->z),
case 3: default => $this,
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;
}
} }
public function distance($x = 0, $y = 0, $z = 0){ public function distance($x = 0, $y = 0, $z = 0){

View file

@ -38,37 +38,9 @@ abstract class RakNetInfo{
const ACK = 0xc0; const ACK = 0xc0;
public static function isValid($pid){ public static function isValid($pid){
switch((int) $pid){ return match ((int)$pid) {
case RakNetInfo::UNCONNECTED_PING: 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,
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS: default => false,
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;
}
} }
} }

View file

@ -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])?|(((?<zwj>\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k<zwj>\\xF0\\x9F..(\k<zwj>\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))"; 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])?|(((?<zwj>\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k<zwj>\\xF0\\x9F..(\k<zwj>\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))";
public static function getEntityTypeByID($id){ public static function getEntityTypeByID($id){
switch($id){ return match ($id) {
case 10: 10, 11, 12, 13, 32, 33, 34, 35, 36 => ENTITY_MOB,
case 11: 62, 65, 80, 81, 82, 83, 84 => ENTITY_OBJECT,
case 12: 66 => FALLING_SAND,
case 13: default => $id,
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;
}
public static function wrapAngleTo360($angle) public static function wrapAngleTo360($angle)
{ {