Migrate all but two remaining legacy enums to native PHP 8.1 enums

This commit is contained in:
Dylan K. Taylor
2023-09-07 19:32:45 +01:00
parent ae564e445d
commit 94d98fb5c4
57 changed files with 1027 additions and 1086 deletions

View File

@@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\utils\EnumTrait;
use pocketmine\utils\LegacyEnumShimTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
@@ -37,48 +37,55 @@ use pocketmine\utils\EnumTrait;
* @method static ToolTier NETHERITE()
* @method static ToolTier STONE()
* @method static ToolTier WOOD()
*
* @phpstan-type TMetadata array{0: int, 1: int, 2: int, 3: int, 4: int}
*/
final class ToolTier{
use EnumTrait {
__construct as Enum___construct;
enum ToolTier{
use LegacyEnumShimTrait;
case WOOD;
case GOLD;
case STONE;
case IRON;
case DIAMOND;
case NETHERITE;
/**
* This function exists only to permit the use of named arguments and to make the code easier to read in PhpStorm.
* @phpstan-return TMetadata
*/
private static function meta(int $harvestLevel, int $maxDurability, int $baseAttackPoints, int $baseEfficiency, int $enchantability) : array{
return [$harvestLevel, $maxDurability, $baseAttackPoints, $baseEfficiency, $enchantability];
}
protected static function setup() : void{
self::registerAll(
new self("wood", 1, 60, 5, 2, 15),
new self("gold", 2, 33, 5, 12, 22),
new self("stone", 3, 132, 6, 4, 5),
new self("iron", 4, 251, 7, 6, 14),
new self("diamond", 5, 1562, 8, 8, 10),
new self("netherite", 6, 2032, 9, 9, 15)
);
}
private function __construct(
string $name,
private int $harvestLevel,
private int $maxDurability,
private int $baseAttackPoints,
private int $baseEfficiency,
private int $enchantability
){
$this->Enum___construct($name);
/**
* @phpstan-return TMetadata
*/
private function getMetadata() : array{
return match($this){
self::WOOD => self::meta(1, 60, 5, 2, 15),
self::GOLD => self::meta(2, 33, 5, 12, 22),
self::STONE => self::meta(3, 132, 6, 4, 5),
self::IRON => self::meta(4, 251, 7, 6, 14),
self::DIAMOND => self::meta(5, 1562, 8, 8, 10),
self::NETHERITE => self::meta(6, 2032, 9, 9, 15)
};
}
public function getHarvestLevel() : int{
return $this->harvestLevel;
return $this->getMetadata()[0];
}
public function getMaxDurability() : int{
return $this->maxDurability;
return $this->getMetadata()[1];
}
public function getBaseAttackPoints() : int{
return $this->baseAttackPoints;
return $this->getMetadata()[2];
}
public function getBaseEfficiency() : int{
return $this->baseEfficiency;
return $this->getMetadata()[3];
}
/**
@@ -88,6 +95,6 @@ final class ToolTier{
* or multiple enchantments upon being enchanted in an enchanting table.
*/
public function getEnchantability() : int{
return $this->enchantability;
return $this->getMetadata()[4];
}
}