Migrate final remaining EnumTrait users to native enums

This commit is contained in:
Dylan K. Taylor
2023-09-08 10:34:12 +01:00
parent 14f2368454
commit 7ce33d9375
15 changed files with 124 additions and 141 deletions

View File

@ -108,33 +108,23 @@ class TypeConverter{
* @internal
*/
public function coreGameModeToProtocol(GameMode $gamemode) : int{
switch($gamemode->id()){
case GameMode::SURVIVAL()->id():
return ProtocolGameMode::SURVIVAL;
case GameMode::CREATIVE()->id():
case GameMode::SPECTATOR()->id():
return ProtocolGameMode::CREATIVE;
case GameMode::ADVENTURE()->id():
return ProtocolGameMode::ADVENTURE;
default:
throw new AssumptionFailedError("Unknown game mode");
}
return match($gamemode){
GameMode::SURVIVAL => ProtocolGameMode::SURVIVAL,
//TODO: native spectator support
GameMode::CREATIVE, GameMode::SPECTATOR => ProtocolGameMode::CREATIVE,
GameMode::ADVENTURE => ProtocolGameMode::ADVENTURE,
};
}
public function protocolGameModeToCore(int $gameMode) : ?GameMode{
switch($gameMode){
case ProtocolGameMode::SURVIVAL:
return GameMode::SURVIVAL();
case ProtocolGameMode::CREATIVE:
return GameMode::CREATIVE();
case ProtocolGameMode::ADVENTURE:
return GameMode::ADVENTURE();
case ProtocolGameMode::CREATIVE_VIEWER:
case ProtocolGameMode::SURVIVAL_VIEWER:
return GameMode::SPECTATOR();
default:
return null;
}
return match($gameMode){
ProtocolGameMode::SURVIVAL => GameMode::SURVIVAL,
ProtocolGameMode::CREATIVE => GameMode::CREATIVE,
ProtocolGameMode::ADVENTURE => GameMode::ADVENTURE,
ProtocolGameMode::SURVIVAL_VIEWER, ProtocolGameMode::CREATIVE_VIEWER => GameMode::SPECTATOR,
//TODO: native spectator support
default => null,
};
}
public function coreRecipeIngredientToNet(?RecipeIngredient $ingredient) : ProtocolRecipeIngredient{

View File

@ -783,7 +783,7 @@ class InGamePacketHandler extends PacketHandler{
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
$gameMode = $this->session->getTypeConverter()->protocolGameModeToCore($packet->gamemode);
if($gameMode === null || !$gameMode->equals($this->player->getGamemode())){
if($gameMode !== $this->player->getGamemode()){
//Set this back to default. TODO: handle this properly
$this->session->syncGameMode($this->player->getGamemode(), true);
}

View File

@ -271,8 +271,8 @@ class RakLibInterface implements ServerEventListener, AdvancedNetworkInterface{
$this->rakServerId,
$this->server->getName(),
match($this->server->getGamemode()){
GameMode::SURVIVAL() => "Survival",
GameMode::ADVENTURE() => "Adventure",
GameMode::SURVIVAL => "Survival",
GameMode::ADVENTURE => "Adventure",
default => "Creative"
}
]) . ";"