PocketMine-MP 5.28.3 git-a4ac28592c6c5f5876927aa2a140b65dad63d786
Loading...
Searching...
No Matches
BannerPatternTypeIdMap.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;
25
26use pocketmine\block\utils\BannerPatternType;
27use pocketmine\utils\SingletonTrait;
28use function array_key_exists;
29use function spl_object_id;
30
32 use SingletonTrait;
33
38 private array $idToEnum = [];
43 private array $enumToId = [];
44
45 public function __construct(){
46 foreach(BannerPatternType::cases() as $case){
47 $this->register(match($case){
48 BannerPatternType::BORDER => "bo",
49 BannerPatternType::BRICKS => "bri",
50 BannerPatternType::CIRCLE => "mc",
51 BannerPatternType::CREEPER => "cre",
52 BannerPatternType::CROSS => "cr",
53 BannerPatternType::CURLY_BORDER => "cbo",
54 BannerPatternType::DIAGONAL_LEFT => "lud",
55 BannerPatternType::DIAGONAL_RIGHT => "rd",
56 BannerPatternType::DIAGONAL_UP_LEFT => "ld",
57 BannerPatternType::DIAGONAL_UP_RIGHT => "rud",
58 BannerPatternType::FLOWER => "flo",
59 BannerPatternType::FLOW => "flw",
60 BannerPatternType::GLOBE => "glb",
61 BannerPatternType::GRADIENT => "gra",
62 BannerPatternType::GRADIENT_UP => "gru",
63 BannerPatternType::GUSTER => "gus",
64 BannerPatternType::HALF_HORIZONTAL => "hh",
65 BannerPatternType::HALF_HORIZONTAL_BOTTOM => "hhb",
66 BannerPatternType::HALF_VERTICAL => "vh",
67 BannerPatternType::HALF_VERTICAL_RIGHT => "vhr",
68 BannerPatternType::MOJANG => "moj",
69 BannerPatternType::PIGLIN => "pig",
70 BannerPatternType::RHOMBUS => "mr",
71 BannerPatternType::SKULL => "sku",
72 BannerPatternType::SMALL_STRIPES => "ss",
73 BannerPatternType::SQUARE_BOTTOM_LEFT => "bl",
74 BannerPatternType::SQUARE_BOTTOM_RIGHT => "br",
75 BannerPatternType::SQUARE_TOP_LEFT => "tl",
76 BannerPatternType::SQUARE_TOP_RIGHT => "tr",
77 BannerPatternType::STRAIGHT_CROSS => "sc",
78 BannerPatternType::STRIPE_BOTTOM => "bs",
79 BannerPatternType::STRIPE_CENTER => "cs",
80 BannerPatternType::STRIPE_DOWNLEFT => "dls",
81 BannerPatternType::STRIPE_DOWNRIGHT => "drs",
82 BannerPatternType::STRIPE_LEFT => "ls",
83 BannerPatternType::STRIPE_MIDDLE => "ms",
84 BannerPatternType::STRIPE_RIGHT => "rs",
85 BannerPatternType::STRIPE_TOP => "ts",
86 BannerPatternType::TRIANGLE_BOTTOM => "bt",
87 BannerPatternType::TRIANGLE_TOP => "tt",
88 BannerPatternType::TRIANGLES_BOTTOM => "bts",
89 BannerPatternType::TRIANGLES_TOP => "tts",
90 }, $case);
91 }
92 }
93
94 public function register(string $stringId, BannerPatternType $type) : void{
95 $this->idToEnum[$stringId] = $type;
96 $this->enumToId[spl_object_id($type)] = $stringId;
97 }
98
99 public function fromId(string $id) : ?BannerPatternType{
100 return $this->idToEnum[$id] ?? null;
101 }
102
103 public function toId(BannerPatternType $type) : string{
104 $k = spl_object_id($type);
105 if(!array_key_exists($k, $this->enumToId)){
106 throw new \InvalidArgumentException("Missing mapping for banner pattern type " . $type->name);
107 }
108 return $this->enumToId[$k];
109 }
110}