diff --git a/src/block/utils/DyeColor.php b/src/block/utils/DyeColor.php index 764e13833..80cb08767 100644 --- a/src/block/utils/DyeColor.php +++ b/src/block/utils/DyeColor.php @@ -57,8 +57,8 @@ final class DyeColor{ /** @var DyeColor[] */ private static $numericIdMap = []; - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new DyeColor("white", "White", 0, new Color(0xf0, 0xf0, 0xf0)), new DyeColor("orange", "Orange", 1, new Color(0xf9, 0x80, 0x1d)), new DyeColor("magenta", "Magenta", 2, new Color(0xc7, 0x4e, 0xbd)), @@ -75,7 +75,7 @@ final class DyeColor{ new DyeColor("green", "Green", 13, new Color(0x5e, 0x7c, 0x16)), new DyeColor("red", "Red", 14, new Color(0xb0, 0x2e, 0x26)), new DyeColor("black", "Black", 15, new Color(0x1d, 0x1d, 0x21)), - ]; + ); } protected static function register(DyeColor $color) : void{ diff --git a/src/block/utils/SkullType.php b/src/block/utils/SkullType.php index 408d68741..43934ff2d 100644 --- a/src/block/utils/SkullType.php +++ b/src/block/utils/SkullType.php @@ -46,15 +46,15 @@ final class SkullType{ /** @var SkullType[] */ private static $numericIdMap = []; - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new SkullType("skeleton", "Skeleton Skull", 0), new SkullType("wither_skeleton", "Wither Skeleton Skull", 1), new SkullType("zombie", "Zombie Head", 2), new SkullType("player", "Player Head", 3), new SkullType("creeper", "Creeper Head", 4), new SkullType("dragon", "Dragon Head", 5) - ]; + ); } protected static function register(SkullType $type) : void{ diff --git a/src/block/utils/SlabType.php b/src/block/utils/SlabType.php index 15035637e..a56cf7ed4 100644 --- a/src/block/utils/SlabType.php +++ b/src/block/utils/SlabType.php @@ -37,11 +37,11 @@ use pocketmine\utils\EnumTrait; final class SlabType{ use EnumTrait; - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new self("bottom"), new self("top"), new self("double") - ]; + ); } } diff --git a/src/block/utils/StairShape.php b/src/block/utils/StairShape.php index 89f4c544a..b46b19f11 100644 --- a/src/block/utils/StairShape.php +++ b/src/block/utils/StairShape.php @@ -39,13 +39,13 @@ use pocketmine\utils\EnumTrait; final class StairShape{ use EnumTrait; - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new self("straight"), new self("inner_left"), new self("inner_right"), new self("outer_left"), new self("outer_right") - ]; + ); } } diff --git a/src/block/utils/TreeType.php b/src/block/utils/TreeType.php index 4d880169a..b3afdd95e 100644 --- a/src/block/utils/TreeType.php +++ b/src/block/utils/TreeType.php @@ -46,15 +46,15 @@ final class TreeType{ /** @var TreeType[] */ private static $numericIdMap = []; - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new TreeType("oak", "Oak", 0), new TreeType("spruce", "Spruce", 1), new TreeType("birch", "Birch", 2), new TreeType("jungle", "Jungle", 3), new TreeType("acacia", "Acacia", 4), new TreeType("dark_oak", "Dark Oak", 5) - ]; + ); } protected static function register(TreeType $type) : void{ diff --git a/src/item/ItemUseResult.php b/src/item/ItemUseResult.php index 7f8bdba01..446945803 100644 --- a/src/item/ItemUseResult.php +++ b/src/item/ItemUseResult.php @@ -37,11 +37,11 @@ use pocketmine\utils\EnumTrait; final class ItemUseResult{ use EnumTrait; - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new self("none"), new self("fail"), new self("success") - ]; + ); } } diff --git a/src/item/ToolTier.php b/src/item/ToolTier.php index 1f2190bb8..30e184e9f 100644 --- a/src/item/ToolTier.php +++ b/src/item/ToolTier.php @@ -41,14 +41,14 @@ final class ToolTier{ __construct as Enum___construct; } - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new self("wood", 1, 60, 5, 2), new self("gold", 2, 33, 5, 12), new self("stone", 3, 132, 6, 4), new self("iron", 4, 251, 7, 6), new self("diamond", 5, 1562, 8, 8) - ]; + ); } /** @var int */ diff --git a/src/player/GameMode.php b/src/player/GameMode.php index b4bab2d41..7d95513ba 100644 --- a/src/player/GameMode.php +++ b/src/player/GameMode.php @@ -47,13 +47,13 @@ final class GameMode{ /** @var self[] */ protected static $magicNumberMap = []; - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new self("survival", 0, "Survival", "gameMode.survival", ["s", "0"]), new self("creative", 1, "Creative", "gameMode.creative", ["c", "1"]), new self("adventure", 2, "Adventure", "gameMode.adventure", ["a", "2"]), new self("spectator", 3, "Spectator", "gameMode.spectator", ["v", "view", "3"]) - ]; + ); } protected static function register(self $member) : void{ diff --git a/src/plugin/PluginLoadOrder.php b/src/plugin/PluginLoadOrder.php index 8e27befcf..fa99eeba9 100644 --- a/src/plugin/PluginLoadOrder.php +++ b/src/plugin/PluginLoadOrder.php @@ -36,10 +36,10 @@ use pocketmine\utils\EnumTrait; final class PluginLoadOrder{ use EnumTrait; - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new self("startup"), new self("postworld") - ]; + ); } } diff --git a/src/utils/EnumTrait.php b/src/utils/EnumTrait.php index 9092bd888..6f6aa517c 100644 --- a/src/utils/EnumTrait.php +++ b/src/utils/EnumTrait.php @@ -38,26 +38,9 @@ trait EnumTrait{ self::_registryRegister($member->name(), $member); } - /** - * Returns an array of enum members to be registered. - * - * (This ought to be private, but traits suck too much for that.) - * - * @return self[]|iterable - */ - abstract protected static function setup() : iterable; - - /** - * @internal Lazy-inits the enum if necessary. - * - * @throws \InvalidArgumentException - */ - protected static function checkInit() : void{ - if(self::$members === null){ - self::$members = []; - foreach(self::setup() as $item){ - self::register($item); - } + protected static function registerAll(self ...$members) : void{ + foreach($members as $member){ + self::register($member); } } diff --git a/src/world/sound/NoteInstrument.php b/src/world/sound/NoteInstrument.php index a6fd778f2..cd37df98a 100644 --- a/src/world/sound/NoteInstrument.php +++ b/src/world/sound/NoteInstrument.php @@ -41,14 +41,14 @@ final class NoteInstrument{ __construct as Enum___construct; } - protected static function setup() : iterable{ - return [ + protected static function setup() : void{ + self::registerAll( new self("piano", 0), new self("bass_drum", 1), new self("snare", 2), new self("clicks_and_sticks", 3), new self("double_bass", 4) - ]; + ); } /** @var int */