PocketMine-MP 5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
ValueMappings.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\data\bedrock\block\convert;
25
26use pocketmine\block\utils\DyeColor;
27use pocketmine\utils\SingletonTrait;
28
29final class ValueMappings{
30 use SingletonTrait; //???
31
36 private array $enumMappings = [];
37
38 public function __construct(){
39 $this->addEnum(DyeColor::class, fn(DyeColor $case) => match ($case) {
40 DyeColor::BLACK => "black",
41 DyeColor::BLUE => "blue",
42 DyeColor::BROWN => "brown",
43 DyeColor::CYAN => "cyan",
44 DyeColor::GRAY => "gray",
45 DyeColor::GREEN => "green",
46 DyeColor::LIGHT_BLUE => "light_blue",
47 DyeColor::LIGHT_GRAY => "light_gray",
48 DyeColor::LIME => "lime",
49 DyeColor::MAGENTA => "magenta",
50 DyeColor::ORANGE => "orange",
51 DyeColor::PINK => "pink",
52 DyeColor::PURPLE => "purple",
53 DyeColor::RED => "red",
54 DyeColor::WHITE => "white",
55 DyeColor::YELLOW => "yellow"
56 });
57 }
58
64 private function addEnum(string $class, \Closure $mapper) : void{
65 $this->enumMappings[$class] = new StringEnumMap($class, $mapper);
66 }
67
73 public function getEnumMap(string $class) : StringEnumMap{
74 if(!isset($this->enumMappings[$class])){
75 throw new \InvalidArgumentException("No enum mapping found for class: $class");
76 }
80 $map = $this->enumMappings[$class];
81 return $map;
82 }
83}