Commits
DerFrZocker authored and md_5 committed 7c0ec598f00
1 1 | package org.bukkit; |
2 2 | |
3 3 | import com.google.common.base.Preconditions; |
4 - | import com.google.common.collect.Maps; |
5 - | import java.util.HashMap; |
4 + | import com.google.common.collect.Lists; |
6 5 | import java.util.Locale; |
6 + | import org.bukkit.packs.DataPack; |
7 + | import org.bukkit.util.OldEnum; |
7 8 | import org.jetbrains.annotations.NotNull; |
8 9 | import org.jetbrains.annotations.Nullable; |
9 10 | |
10 11 | /** |
11 - | * Represents the art on a painting |
12 + | * Represents the art on a painting. |
13 + | * <p> |
14 + | * The arts listed in this interface are present in the default server |
15 + | * or can be enabled via a {@link FeatureFlag}. |
16 + | * There may be additional arts present in the server, for example from a {@link DataPack} |
17 + | * which can be accessed via {@link Registry#ART}. |
12 18 | */ |
13 - | public enum Art implements Keyed { |
14 - | KEBAB(0, 1, 1), |
15 - | AZTEC(1, 1, 1), |
16 - | ALBAN(2, 1, 1), |
17 - | AZTEC2(3, 1, 1), |
18 - | BOMB(4, 1, 1), |
19 - | PLANT(5, 1, 1), |
20 - | WASTELAND(6, 1, 1), |
21 - | POOL(7, 2, 1), |
22 - | COURBET(8, 2, 1), |
23 - | SEA(9, 2, 1), |
24 - | SUNSET(10, 2, 1), |
25 - | CREEBET(11, 2, 1), |
26 - | WANDERER(12, 1, 2), |
27 - | GRAHAM(13, 1, 2), |
28 - | MATCH(14, 2, 2), |
29 - | BUST(15, 2, 2), |
30 - | STAGE(16, 2, 2), |
31 - | VOID(17, 2, 2), |
32 - | SKULL_AND_ROSES(18, 2, 2), |
33 - | WITHER(19, 2, 2), |
34 - | FIGHTERS(20, 4, 2), |
35 - | POINTER(21, 4, 4), |
36 - | PIGSCENE(22, 4, 4), |
37 - | BURNING_SKULL(23, 4, 4), |
38 - | SKELETON(24, 4, 3), |
39 - | DONKEY_KONG(25, 4, 3), |
40 - | EARTH(26, 2, 2), |
41 - | WIND(27, 2, 2), |
42 - | WATER(28, 2, 2), |
43 - | FIRE(29, 2, 2), |
44 - | BAROQUE(30, 2, 2), |
45 - | HUMBLE(31, 2, 2), |
46 - | MEDITATIVE(32, 1, 1), |
47 - | PRAIRIE_RIDE(33, 1, 2), |
48 - | UNPACKED(34, 4, 4), |
49 - | BACKYARD(35, 3, 4), |
50 - | BOUQUET(36, 3, 3), |
51 - | CAVEBIRD(37, 3, 3), |
52 - | CHANGING(38, 4, 2), |
53 - | COTAN(39, 3, 3), |
54 - | ENDBOSS(40, 3, 3), |
55 - | FERN(41, 3, 3), |
56 - | FINDING(42, 4, 2), |
57 - | LOWMIST(43, 4, 2), |
58 - | ORB(44, 4, 4), |
59 - | OWLEMONS(45, 3, 3), |
60 - | PASSAGE(46, 4, 2), |
61 - | POND(47, 3, 4), |
62 - | SUNFLOWERS(48, 3, 3), |
63 - | TIDES(49, 3, 3); |
19 + | public interface Art extends OldEnum<Art>, Keyed { |
64 20 | |
65 - | private final int id, width, height; |
66 - | private final NamespacedKey key; |
67 - | private static final HashMap<String, Art> BY_NAME = Maps.newHashMap(); |
68 - | private static final HashMap<Integer, Art> BY_ID = Maps.newHashMap(); |
21 + | Art KEBAB = getArt("kebab"); |
22 + | Art AZTEC = getArt("aztec"); |
23 + | Art ALBAN = getArt("alban"); |
24 + | Art AZTEC2 = getArt("aztec2"); |
25 + | Art BOMB = getArt("bomb"); |
26 + | Art PLANT = getArt("plant"); |
27 + | Art WASTELAND = getArt("wasteland"); |
28 + | Art POOL = getArt("pool"); |
29 + | Art COURBET = getArt("courbet"); |
30 + | Art SEA = getArt("sea"); |
31 + | Art SUNSET = getArt("sunset"); |
32 + | Art CREEBET = getArt("creebet"); |
33 + | Art WANDERER = getArt("wanderer"); |
34 + | Art GRAHAM = getArt("graham"); |
35 + | Art MATCH = getArt("match"); |
36 + | Art BUST = getArt("bust"); |
37 + | Art STAGE = getArt("stage"); |
38 + | Art VOID = getArt("void"); |
39 + | Art SKULL_AND_ROSES = getArt("skull_and_roses"); |
40 + | Art WITHER = getArt("wither"); |
41 + | Art FIGHTERS = getArt("fighters"); |
42 + | Art POINTER = getArt("pointer"); |
43 + | Art PIGSCENE = getArt("pigscene"); |
44 + | Art BURNING_SKULL = getArt("burning_skull"); |
45 + | Art SKELETON = getArt("skeleton"); |
46 + | Art DONKEY_KONG = getArt("donkey_kong"); |
47 + | Art EARTH = getArt("earth"); |
48 + | Art WIND = getArt("wind"); |
49 + | Art WATER = getArt("water"); |
50 + | Art FIRE = getArt("fire"); |
51 + | Art BAROQUE = getArt("baroque"); |
52 + | Art HUMBLE = getArt("humble"); |
53 + | Art MEDITATIVE = getArt("meditative"); |
54 + | Art PRAIRIE_RIDE = getArt("prairie_ride"); |
55 + | Art UNPACKED = getArt("unpacked"); |
56 + | Art BACKYARD = getArt("backyard"); |
57 + | Art BOUQUET = getArt("bouquet"); |
58 + | Art CAVEBIRD = getArt("cavebird"); |
59 + | Art CHANGING = getArt("changing"); |
60 + | Art COTAN = getArt("cotan"); |
61 + | Art ENDBOSS = getArt("endboss"); |
62 + | Art FERN = getArt("fern"); |
63 + | Art FINDING = getArt("finding"); |
64 + | Art LOWMIST = getArt("lowmist"); |
65 + | Art ORB = getArt("orb"); |
66 + | Art OWLEMONS = getArt("owlemons"); |
67 + | Art PASSAGE = getArt("passage"); |
68 + | Art POND = getArt("pond"); |
69 + | Art SUNFLOWERS = getArt("sunflowers"); |
70 + | Art TIDES = getArt("tides"); |
69 71 | |
70 - | private Art(int id, int width, int height) { |
71 - | this.id = id; |
72 - | this.width = width; |
73 - | this.height = height; |
74 - | this.key = NamespacedKey.minecraft(name().toLowerCase(Locale.ROOT)); |
72 + | |
73 + | private static Art getArt( String key) { |
74 + | return Registry.ART.getOrThrow(NamespacedKey.minecraft(key)); |
75 75 | } |
76 76 | |
77 77 | /** |
78 78 | * Gets the width of the painting, in blocks |
79 79 | * |
80 80 | * @return The width of the painting, in blocks |
81 81 | */ |
82 - | public int getBlockWidth() { |
83 - | return width; |
84 - | } |
82 + | int getBlockWidth(); |
85 83 | |
86 84 | /** |
87 85 | * Gets the height of the painting, in blocks |
88 86 | * |
89 87 | * @return The height of the painting, in blocks |
90 88 | */ |
91 - | public int getBlockHeight() { |
92 - | return height; |
93 - | } |
89 + | int getBlockHeight(); |
94 90 | |
95 91 | /** |
96 92 | * Get the ID of this painting. |
97 93 | * |
98 94 | * @return The ID of this painting |
99 95 | * @deprecated Magic value |
100 96 | */ |
101 - | |
102 - | public int getId() { |
103 - | return id; |
104 - | } |
105 - | |
106 - | |
107 - | |
108 - | public NamespacedKey getKey() { |
109 - | return key; |
110 - | } |
97 + | since = "1.6.2") | (
98 + | int getId(); |
111 99 | |
112 100 | /** |
113 101 | * Get a painting by its numeric ID |
114 102 | * |
115 103 | * @param id The ID |
116 104 | * @return The painting |
117 105 | * @deprecated Magic value |
118 106 | */ |
119 - | |
107 + | (since = "1.6.2") |
120 108 | |
121 - | public static Art getById(int id) { |
122 - | return BY_ID.get(id); |
109 + | static Art getById(int id) { |
110 + | for (Art art : Registry.ART) { |
111 + | if (id == art.getId()) { |
112 + | return art; |
113 + | } |
114 + | } |
115 + | |
116 + | return null; |
123 117 | } |
124 118 | |
125 119 | /** |
126 120 | * Get a painting by its unique name |
127 121 | * <p> |
128 - | * This ignores underscores and capitalization |
122 + | * This ignores capitalization |
129 123 | * |
130 124 | * @param name The name |
131 125 | * @return The painting |
126 + | * @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead. |
132 127 | */ |
128 + | since = "1.21.3") | (
133 129 | |
134 - | public static Art getByName( String name) { |
130 + | static Art getByName( String name) { |
135 131 | Preconditions.checkArgument(name != null, "Name cannot be null"); |
136 132 | |
137 - | return BY_NAME.get(name.toLowerCase(Locale.ROOT)); |
133 + | return Bukkit.getUnsafe().get(Registry.ART, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); |
138 134 | } |
139 135 | |
140 - | static { |
141 - | for (Art art : values()) { |
142 - | BY_ID.put(art.id, art); |
143 - | BY_NAME.put(art.toString().toLowerCase(Locale.ROOT), art); |
144 - | } |
136 + | /** |
137 + | * @param name of the art. |
138 + | * @return the art with the given name. |
139 + | * @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead. |
140 + | */ |
141 + | |
142 + | (since = "1.21.3") |
143 + | static Art valueOf( String name) { |
144 + | Art art = Bukkit.getUnsafe().get(Registry.ART, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); |
145 + | Preconditions.checkArgument(art != null, "No art found with the name %s", name); |
146 + | return art; |
147 + | } |
148 + | |
149 + | /** |
150 + | * @return an array of all known arts. |
151 + | * @deprecated use {@link Registry#iterator()}. |
152 + | */ |
153 + | |
154 + | since = "1.21.3") ( |
155 + | static Art[] values() { |
156 + | return Lists.newArrayList(Registry.ART).toArray(new Art[0]); |
145 157 | } |
146 158 | } |