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

@ -372,7 +372,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->lastPlayed = $nbt->getLong(self::TAG_LAST_PLAYED, $now);
if(!$this->server->getForceGamemode() && ($gameModeTag = $nbt->getTag(self::TAG_GAME_MODE)) instanceof IntTag){
$this->internalSetGameMode(GameModeIdMap::getInstance()->fromId($gameModeTag->getValue()) ?? GameMode::SURVIVAL()); //TODO: bad hack here to avoid crashes on corrupted data
$this->internalSetGameMode(GameModeIdMap::getInstance()->fromId($gameModeTag->getValue()) ?? GameMode::SURVIVAL); //TODO: bad hack here to avoid crashes on corrupted data
}else{
$this->internalSetGameMode($this->server->getGamemode());
}
@ -1113,7 +1113,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
protected function internalSetGameMode(GameMode $gameMode) : void{
$this->gamemode = $gameMode;
$this->allowFlight = $this->gamemode->equals(GameMode::CREATIVE());
$this->allowFlight = $this->gamemode === GameMode::CREATIVE;
$this->hungerManager->setEnabled($this->isSurvival());
if($this->isSpectator()){
@ -1139,7 +1139,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* Sets the provided gamemode.
*/
public function setGamemode(GameMode $gm) : bool{
if($this->gamemode->equals($gm)){
if($this->gamemode === $gm){
return false;
}
@ -1168,7 +1168,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* @param bool $literal whether a literal check should be performed
*/
public function isSurvival(bool $literal = false) : bool{
return $this->gamemode->equals(GameMode::SURVIVAL()) || (!$literal && $this->gamemode->equals(GameMode::ADVENTURE()));
return $this->gamemode === GameMode::SURVIVAL || (!$literal && $this->gamemode === GameMode::ADVENTURE);
}
/**
@ -1178,7 +1178,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* @param bool $literal whether a literal check should be performed
*/
public function isCreative(bool $literal = false) : bool{
return $this->gamemode->equals(GameMode::CREATIVE()) || (!$literal && $this->gamemode->equals(GameMode::SPECTATOR()));
return $this->gamemode === GameMode::CREATIVE || (!$literal && $this->gamemode === GameMode::SPECTATOR);
}
/**
@ -1188,18 +1188,18 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* @param bool $literal whether a literal check should be performed
*/
public function isAdventure(bool $literal = false) : bool{
return $this->gamemode->equals(GameMode::ADVENTURE()) || (!$literal && $this->gamemode->equals(GameMode::SPECTATOR()));
return $this->gamemode === GameMode::ADVENTURE || (!$literal && $this->gamemode === GameMode::SPECTATOR);
}
public function isSpectator() : bool{
return $this->gamemode->equals(GameMode::SPECTATOR());
return $this->gamemode === GameMode::SPECTATOR;
}
/**
* TODO: make this a dynamic ability instead of being hardcoded
*/
public function hasFiniteResources() : bool{
return !$this->gamemode->equals(GameMode::CREATIVE());
return $this->gamemode !== GameMode::CREATIVE;
}
public function getDrops() : array{