mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-04-13 09:41:09 +00:00
Add MapCursor Type
This commit is contained in:
parent
2bbde59dba
commit
a8b4d2f9a2
2 changed files with 73 additions and 53 deletions
|
@ -299,7 +299,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||
* @see MapCursor.Type
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
Registry<MapCursor.Type> MAP_DECORATION_TYPE = new SimpleRegistry<>(MapCursor.Type.class);
|
||||
Registry<MapCursor.Type> MAP_DECORATION_TYPE = Objects.requireNonNull(Bukkit.getRegistry(MapCursor.Type.class), "No registry present for Map Type. This is a bug.");
|
||||
/**
|
||||
* Game events.
|
||||
*
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package org.bukkit.map;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.util.OldEnum;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -176,7 +181,7 @@ public final class MapCursor {
|
|||
* @param type The type (color/style) of the map cursor.
|
||||
*/
|
||||
public void setType(@NotNull Type type) {
|
||||
setRawType(type.value);
|
||||
setRawType(type.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,56 +232,50 @@ public final class MapCursor {
|
|||
* index in the file './assets/minecraft/textures/map/map_icons.png' from minecraft.jar or from a
|
||||
* resource pack.
|
||||
*/
|
||||
public enum Type implements Keyed {
|
||||
PLAYER(0, "player"),
|
||||
FRAME(1, "frame"),
|
||||
RED_MARKER(2, "red_marker"),
|
||||
BLUE_MARKER(3, "blue_marker"),
|
||||
TARGET_X(4, "target_x"),
|
||||
TARGET_POINT(5, "target_point"),
|
||||
PLAYER_OFF_MAP(6, "player_off_map"),
|
||||
PLAYER_OFF_LIMITS(7, "player_off_limits"),
|
||||
MANSION(8, "mansion"),
|
||||
MONUMENT(9, "monument"),
|
||||
BANNER_WHITE(10, "banner_white"),
|
||||
BANNER_ORANGE(11, "banner_orange"),
|
||||
BANNER_MAGENTA(12, "banner_magenta"),
|
||||
BANNER_LIGHT_BLUE(13, "banner_light_blue"),
|
||||
BANNER_YELLOW(14, "banner_yellow"),
|
||||
BANNER_LIME(15, "banner_lime"),
|
||||
BANNER_PINK(16, "banner_pink"),
|
||||
BANNER_GRAY(17, "banner_gray"),
|
||||
BANNER_LIGHT_GRAY(18, "banner_light_gray"),
|
||||
BANNER_CYAN(19, "banner_cyan"),
|
||||
BANNER_PURPLE(20, "banner_purple"),
|
||||
BANNER_BLUE(21, "banner_blue"),
|
||||
BANNER_BROWN(22, "banner_brown"),
|
||||
BANNER_GREEN(23, "banner_green"),
|
||||
BANNER_RED(24, "banner_red"),
|
||||
BANNER_BLACK(25, "banner_black"),
|
||||
RED_X(26, "red_x"),
|
||||
VILLAGE_DESERT(27, "village_desert"),
|
||||
VILLAGE_PLAINS(28, "village_plains"),
|
||||
VILLAGE_SAVANNA(29, "village_savanna"),
|
||||
VILLAGE_SNOWY(30, "village_snowy"),
|
||||
VILLAGE_TAIGA(31, "village_taiga"),
|
||||
JUNGLE_TEMPLE(32, "jungle_temple"),
|
||||
SWAMP_HUT(33, "swamp_hut"),
|
||||
TRIAL_CHAMBERS(34, "trial_chambers")
|
||||
;
|
||||
public abstract static class Type implements OldEnum<Type>, Keyed {
|
||||
|
||||
private byte value;
|
||||
private final NamespacedKey key;
|
||||
|
||||
private Type(int value, String key) {
|
||||
this.value = (byte) value;
|
||||
this.key = NamespacedKey.minecraft(key);
|
||||
}
|
||||
public static final Type PLAYER = getType("player");
|
||||
public static final Type FRAME = getType("frame");
|
||||
public static final Type RED_MARKER = getType("red_marker");
|
||||
public static final Type BLUE_MARKER = getType("blue_marker");
|
||||
public static final Type TARGET_X = getType("target_x");
|
||||
public static final Type TARGET_POINT = getType("target_point");
|
||||
public static final Type PLAYER_OFF_MAP = getType("player_off_map");
|
||||
public static final Type PLAYER_OFF_LIMITS = getType("player_off_limits");
|
||||
public static final Type MANSION = getType("mansion");
|
||||
public static final Type MONUMENT = getType("monument");
|
||||
public static final Type BANNER_WHITE = getType("banner_white");
|
||||
public static final Type BANNER_ORANGE = getType("banner_orange");
|
||||
public static final Type BANNER_MAGENTA = getType("banner_magenta");
|
||||
public static final Type BANNER_LIGHT_BLUE = getType("banner_light_blue");
|
||||
public static final Type BANNER_YELLOW = getType("banner_yellow");
|
||||
public static final Type BANNER_LIME = getType("banner_lime");
|
||||
public static final Type BANNER_PINK = getType("banner_pink");
|
||||
public static final Type BANNER_GRAY = getType("banner_gray");
|
||||
public static final Type BANNER_LIGHT_GRAY = getType("banner_light_gray");
|
||||
public static final Type BANNER_CYAN = getType("banner_cyan");
|
||||
public static final Type BANNER_PURPLE = getType("banner_purple");
|
||||
public static final Type BANNER_BLUE = getType("banner_blue");
|
||||
public static final Type BANNER_BROWN = getType("banner_brown");
|
||||
public static final Type BANNER_GREEN = getType("banner_green");
|
||||
public static final Type BANNER_RED = getType("banner_red");
|
||||
public static final Type BANNER_BLACK = getType("banner_black");
|
||||
public static final Type RED_X = getType("red_x");
|
||||
public static final Type VILLAGE_DESERT = getType("village_desert");
|
||||
public static final Type VILLAGE_PLAINS = getType("village_plains");
|
||||
public static final Type VILLAGE_SAVANNA = getType("village_savanna");
|
||||
public static final Type VILLAGE_SNOWY = getType("village_snowy");
|
||||
public static final Type VILLAGE_TAIGA = getType("village_taiga");
|
||||
public static final Type JUNGLE_TEMPLE = getType("jungle_temple");
|
||||
public static final Type SWAMP_HUT = getType("swamp_hut");
|
||||
public static final Type TRIAL_CHAMBERS = getType("trial_chambers");
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
private static Type getType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Type type = Registry.MAP_DECORATION_TYPE.get(namespacedKey);
|
||||
Preconditions.checkNotNull(type, "No type found for %s. This is a bug.", namespacedKey);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -286,9 +285,7 @@ public final class MapCursor {
|
|||
* @deprecated Magic value
|
||||
*/
|
||||
@Deprecated
|
||||
public byte getValue() {
|
||||
return value;
|
||||
}
|
||||
public abstract byte getValue();
|
||||
|
||||
/**
|
||||
* Get a cursor by its internal value.
|
||||
|
@ -301,10 +298,33 @@ public final class MapCursor {
|
|||
@Nullable
|
||||
public static Type byValue(byte value) {
|
||||
for (Type t : values()) {
|
||||
if (t.value == value) return t;
|
||||
if (t.getValue() == value) return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name of the type.
|
||||
* @return the type with the given name.
|
||||
* @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static Type valueOf(@NotNull String name) {
|
||||
Type type = Registry.MAP_DECORATION_TYPE.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
|
||||
Preconditions.checkArgument(type != null, "No Type found with the name %s", name);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of all known map cursor types.
|
||||
* @deprecated use {@link Registry#iterator()}.
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static Type[] values() {
|
||||
return Lists.newArrayList(Registry.MAP_DECORATION_TYPE).toArray(new Type[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue