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)){
$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();

View file

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