mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Migrate final remaining EnumTrait users to native enums
This commit is contained in:
@ -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{
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
]) . ";"
|
||||
|
Reference in New Issue
Block a user