Commits

DerFrZocker authored a8b4d2f9a20
Add MapCursor Type
No tags
experimental

src/main/java/org/bukkit/map/MapCursor.java

Modified
1 1 package org.bukkit.map;
2 2
3 +import com.google.common.base.Preconditions;
4 +import com.google.common.collect.Lists;
5 +import java.util.Locale;
3 6 import org.bukkit.Keyed;
4 7 import org.bukkit.NamespacedKey;
8 +import org.bukkit.Registry;
9 +import org.bukkit.util.OldEnum;
5 10 import org.jetbrains.annotations.NotNull;
6 11 import org.jetbrains.annotations.Nullable;
7 12
8 13 /**
9 14 * Represents a cursor on a map.
10 15 */
11 16 public final class MapCursor {
12 17 private byte x, y;
13 18 private byte direction, type;
14 19 private boolean visible;
169 174 }
170 175 this.direction = direction;
171 176 }
172 177
173 178 /**
174 179 * Set the type of this cursor.
175 180 *
176 181 * @param type The type (color/style) of the map cursor.
177 182 */
178 183 public void setType(@NotNull Type type) {
179 - setRawType(type.value);
184 + setRawType(type.getValue());
180 185 }
181 186
182 187 /**
183 188 * Set the type of this cursor.
184 189 *
185 190 * @param type The type (color/style) of the map cursor.
186 191 * @deprecated Magic value
187 192 */
188 193 @Deprecated
189 194 public void setRawType(byte type) {
220 225 public void setCaption(@Nullable String caption) {
221 226 this.caption = caption;
222 227 }
223 228
224 229 /**
225 230 * Represents the standard types of map cursors. More may be made
226 231 * available by resource packs - the value is used by the client as an
227 232 * index in the file './assets/minecraft/textures/map/map_icons.png' from minecraft.jar or from a
228 233 * resource pack.
229 234 */
230 - public enum Type implements Keyed {
231 - PLAYER(0, "player"),
232 - FRAME(1, "frame"),
233 - RED_MARKER(2, "red_marker"),
234 - BLUE_MARKER(3, "blue_marker"),
235 - TARGET_X(4, "target_x"),
236 - TARGET_POINT(5, "target_point"),
237 - PLAYER_OFF_MAP(6, "player_off_map"),
238 - PLAYER_OFF_LIMITS(7, "player_off_limits"),
239 - MANSION(8, "mansion"),
240 - MONUMENT(9, "monument"),
241 - BANNER_WHITE(10, "banner_white"),
242 - BANNER_ORANGE(11, "banner_orange"),
243 - BANNER_MAGENTA(12, "banner_magenta"),
244 - BANNER_LIGHT_BLUE(13, "banner_light_blue"),
245 - BANNER_YELLOW(14, "banner_yellow"),
246 - BANNER_LIME(15, "banner_lime"),
247 - BANNER_PINK(16, "banner_pink"),
248 - BANNER_GRAY(17, "banner_gray"),
249 - BANNER_LIGHT_GRAY(18, "banner_light_gray"),
250 - BANNER_CYAN(19, "banner_cyan"),
251 - BANNER_PURPLE(20, "banner_purple"),
252 - BANNER_BLUE(21, "banner_blue"),
253 - BANNER_BROWN(22, "banner_brown"),
254 - BANNER_GREEN(23, "banner_green"),
255 - BANNER_RED(24, "banner_red"),
256 - BANNER_BLACK(25, "banner_black"),
257 - RED_X(26, "red_x"),
258 - VILLAGE_DESERT(27, "village_desert"),
259 - VILLAGE_PLAINS(28, "village_plains"),
260 - VILLAGE_SAVANNA(29, "village_savanna"),
261 - VILLAGE_SNOWY(30, "village_snowy"),
262 - VILLAGE_TAIGA(31, "village_taiga"),
263 - JUNGLE_TEMPLE(32, "jungle_temple"),
264 - SWAMP_HUT(33, "swamp_hut"),
265 - TRIAL_CHAMBERS(34, "trial_chambers")
266 - ;
235 + public abstract static class Type implements OldEnum<Type>, Keyed {
267 236
268 - private byte value;
269 - private final NamespacedKey key;
270 -
271 - private Type(int value, String key) {
272 - this.value = (byte) value;
273 - this.key = NamespacedKey.minecraft(key);
274 - }
237 + public static final Type PLAYER = getType("player");
238 + public static final Type FRAME = getType("frame");
239 + public static final Type RED_MARKER = getType("red_marker");
240 + public static final Type BLUE_MARKER = getType("blue_marker");
241 + public static final Type TARGET_X = getType("target_x");
242 + public static final Type TARGET_POINT = getType("target_point");
243 + public static final Type PLAYER_OFF_MAP = getType("player_off_map");
244 + public static final Type PLAYER_OFF_LIMITS = getType("player_off_limits");
245 + public static final Type MANSION = getType("mansion");
246 + public static final Type MONUMENT = getType("monument");
247 + public static final Type BANNER_WHITE = getType("banner_white");
248 + public static final Type BANNER_ORANGE = getType("banner_orange");
249 + public static final Type BANNER_MAGENTA = getType("banner_magenta");
250 + public static final Type BANNER_LIGHT_BLUE = getType("banner_light_blue");
251 + public static final Type BANNER_YELLOW = getType("banner_yellow");
252 + public static final Type BANNER_LIME = getType("banner_lime");
253 + public static final Type BANNER_PINK = getType("banner_pink");
254 + public static final Type BANNER_GRAY = getType("banner_gray");
255 + public static final Type BANNER_LIGHT_GRAY = getType("banner_light_gray");
256 + public static final Type BANNER_CYAN = getType("banner_cyan");
257 + public static final Type BANNER_PURPLE = getType("banner_purple");
258 + public static final Type BANNER_BLUE = getType("banner_blue");
259 + public static final Type BANNER_BROWN = getType("banner_brown");
260 + public static final Type BANNER_GREEN = getType("banner_green");
261 + public static final Type BANNER_RED = getType("banner_red");
262 + public static final Type BANNER_BLACK = getType("banner_black");
263 + public static final Type RED_X = getType("red_x");
264 + public static final Type VILLAGE_DESERT = getType("village_desert");
265 + public static final Type VILLAGE_PLAINS = getType("village_plains");
266 + public static final Type VILLAGE_SAVANNA = getType("village_savanna");
267 + public static final Type VILLAGE_SNOWY = getType("village_snowy");
268 + public static final Type VILLAGE_TAIGA = getType("village_taiga");
269 + public static final Type JUNGLE_TEMPLE = getType("jungle_temple");
270 + public static final Type SWAMP_HUT = getType("swamp_hut");
271 + public static final Type TRIAL_CHAMBERS = getType("trial_chambers");
275 272
276 273 @NotNull
277 - @Override
278 - public NamespacedKey getKey() {
279 - return key;
274 + private static Type getType(@NotNull String key) {
275 + NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
276 + Type type = Registry.MAP_DECORATION_TYPE.get(namespacedKey);
277 + Preconditions.checkNotNull(type, "No type found for %s. This is a bug.", namespacedKey);
278 + return type;
280 279 }
281 280
282 281 /**
283 282 * Gets the internal value of the cursor.
284 283 *
285 284 * @return the value
286 285 * @deprecated Magic value
287 286 */
288 287 @Deprecated
289 - public byte getValue() {
290 - return value;
291 - }
288 + public abstract byte getValue();
292 289
293 290 /**
294 291 * Get a cursor by its internal value.
295 292 *
296 293 * @param value the value
297 294 * @return the matching type
298 295 * @deprecated Magic value
299 296 */
300 297 @Deprecated
301 298 @Nullable
302 299 public static Type byValue(byte value) {
303 300 for (Type t : values()) {
304 - if (t.value == value) return t;
301 + if (t.getValue() == value) return t;
305 302 }
306 303 return null;
307 304 }
305 +
306 + /**
307 + * @param name of the type.
308 + * @return the type with the given name.
309 + * @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
310 + */
311 + @NotNull
312 + @Deprecated
313 + public static Type valueOf(@NotNull String name) {
314 + Type type = Registry.MAP_DECORATION_TYPE.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
315 + Preconditions.checkArgument(type != null, "No Type found with the name %s", name);
316 + return type;
317 + }
318 +
319 + /**
320 + * @return an array of all known map cursor types.
321 + * @deprecated use {@link Registry#iterator()}.
322 + */
323 + @NotNull
324 + @Deprecated
325 + public static Type[] values() {
326 + return Lists.newArrayList(Registry.MAP_DECORATION_TYPE).toArray(new Type[0]);
327 + }
308 328 }
309 329
310 330 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut