mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-09 00:22:08 -07:00
SPIGOT-7837: Support data pack banner patterns
By: Doc <nachito94@msn.com>
This commit is contained in:
@@ -88,7 +88,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||||||
*
|
*
|
||||||
* @see PatternType
|
* @see PatternType
|
||||||
*/
|
*/
|
||||||
Registry<PatternType> BANNER_PATTERN = new SimpleRegistry<>(PatternType.class);
|
Registry<PatternType> BANNER_PATTERN = Objects.requireNonNull(Bukkit.getRegistry(PatternType.class), "No registry present for Pattern Type. This is a bug.");
|
||||||
/**
|
/**
|
||||||
* Server biomes.
|
* Server biomes.
|
||||||
*
|
*
|
||||||
|
@@ -1,79 +1,64 @@
|
|||||||
package org.bukkit.block.banner;
|
package org.bukkit.block.banner;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import com.google.common.base.Preconditions;
|
||||||
import java.util.Map;
|
import com.google.common.collect.Lists;
|
||||||
|
import java.util.Locale;
|
||||||
import org.bukkit.Keyed;
|
import org.bukkit.Keyed;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.Registry;
|
import org.bukkit.Registry;
|
||||||
|
import org.bukkit.util.OldEnum;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public enum PatternType implements Keyed {
|
public interface PatternType extends OldEnum<PatternType>, Keyed {
|
||||||
BASE("b", "base"),
|
PatternType BASE = getType("base");
|
||||||
SQUARE_BOTTOM_LEFT("bl", "square_bottom_left"),
|
PatternType SQUARE_BOTTOM_LEFT = getType("square_bottom_left");
|
||||||
SQUARE_BOTTOM_RIGHT("br", "square_bottom_right"),
|
PatternType SQUARE_BOTTOM_RIGHT = getType("square_bottom_right");
|
||||||
SQUARE_TOP_LEFT("tl", "square_top_left"),
|
PatternType SQUARE_TOP_LEFT = getType("square_top_left");
|
||||||
SQUARE_TOP_RIGHT("tr", "square_top_right"),
|
PatternType SQUARE_TOP_RIGHT = getType("square_top_right");
|
||||||
STRIPE_BOTTOM("bs", "stripe_bottom"),
|
PatternType STRIPE_BOTTOM = getType("stripe_bottom");
|
||||||
STRIPE_TOP("ts", "stripe_top"),
|
PatternType STRIPE_TOP = getType("stripe_top");
|
||||||
STRIPE_LEFT("ls", "stripe_left"),
|
PatternType STRIPE_LEFT = getType("stripe_left");
|
||||||
STRIPE_RIGHT("rs", "stripe_right"),
|
PatternType STRIPE_RIGHT = getType("stripe_right");
|
||||||
STRIPE_CENTER("cs", "stripe_center"),
|
PatternType STRIPE_CENTER = getType("stripe_center");
|
||||||
STRIPE_MIDDLE("ms", "stripe_middle"),
|
PatternType STRIPE_MIDDLE = getType("stripe_middle");
|
||||||
STRIPE_DOWNRIGHT("drs", "stripe_downright"),
|
PatternType STRIPE_DOWNRIGHT = getType("stripe_downright");
|
||||||
STRIPE_DOWNLEFT("dls", "stripe_downleft"),
|
PatternType STRIPE_DOWNLEFT = getType("stripe_downleft");
|
||||||
SMALL_STRIPES("ss", "small_stripes"),
|
PatternType SMALL_STRIPES = getType("small_stripes");
|
||||||
CROSS("cr", "cross"),
|
PatternType CROSS = getType("cross");
|
||||||
STRAIGHT_CROSS("sc", "straight_cross"),
|
PatternType STRAIGHT_CROSS = getType("straight_cross");
|
||||||
TRIANGLE_BOTTOM("bt", "triangle_bottom"),
|
PatternType TRIANGLE_BOTTOM = getType("triangle_bottom");
|
||||||
TRIANGLE_TOP("tt", "triangle_top"),
|
PatternType TRIANGLE_TOP = getType("triangle_top");
|
||||||
TRIANGLES_BOTTOM("bts", "triangles_bottom"),
|
PatternType TRIANGLES_BOTTOM = getType("triangles_bottom");
|
||||||
TRIANGLES_TOP("tts", "triangles_top"),
|
PatternType TRIANGLES_TOP = getType("triangles_top");
|
||||||
DIAGONAL_LEFT("ld", "diagonal_left"),
|
PatternType DIAGONAL_LEFT = getType("diagonal_left");
|
||||||
DIAGONAL_UP_RIGHT("rd", "diagonal_up_right"),
|
PatternType DIAGONAL_UP_RIGHT = getType("diagonal_up_right");
|
||||||
DIAGONAL_UP_LEFT("lud", "diagonal_up_left"),
|
PatternType DIAGONAL_UP_LEFT = getType("diagonal_up_left");
|
||||||
DIAGONAL_RIGHT("rud", "diagonal_right"),
|
PatternType DIAGONAL_RIGHT = getType("diagonal_right");
|
||||||
CIRCLE("mc", "circle"),
|
PatternType CIRCLE = getType("circle");
|
||||||
RHOMBUS("mr", "rhombus"),
|
PatternType RHOMBUS = getType("rhombus");
|
||||||
HALF_VERTICAL("vh", "half_vertical"),
|
PatternType HALF_VERTICAL = getType("half_vertical");
|
||||||
HALF_HORIZONTAL("hh", "half_horizontal"),
|
PatternType HALF_HORIZONTAL = getType("half_horizontal");
|
||||||
HALF_VERTICAL_RIGHT("vhr", "half_vertical_right"),
|
PatternType HALF_VERTICAL_RIGHT = getType("half_vertical_right");
|
||||||
HALF_HORIZONTAL_BOTTOM("hhb", "half_horizontal_bottom"),
|
PatternType HALF_HORIZONTAL_BOTTOM = getType("half_horizontal_bottom");
|
||||||
BORDER("bo", "border"),
|
PatternType BORDER = getType("border");
|
||||||
CURLY_BORDER("cbo", "curly_border"),
|
PatternType CURLY_BORDER = getType("curly_border");
|
||||||
CREEPER("cre", "creeper"),
|
PatternType CREEPER = getType("creeper");
|
||||||
GRADIENT("gra", "gradient"),
|
PatternType GRADIENT = getType("gradient");
|
||||||
GRADIENT_UP("gru", "gradient_up"),
|
PatternType GRADIENT_UP = getType("gradient_up");
|
||||||
BRICKS("bri", "bricks"),
|
PatternType BRICKS = getType("bricks");
|
||||||
SKULL("sku", "skull"),
|
PatternType SKULL = getType("skull");
|
||||||
FLOWER("flo", "flower"),
|
PatternType FLOWER = getType("flower");
|
||||||
MOJANG("moj", "mojang"),
|
PatternType MOJANG = getType("mojang");
|
||||||
GLOBE("glb", "globe"),
|
PatternType GLOBE = getType("globe");
|
||||||
PIGLIN("pig", "piglin"),
|
PatternType PIGLIN = getType("piglin");
|
||||||
FLOW("flw", "flow"),
|
PatternType FLOW = getType("flow");
|
||||||
GUSTER("gus", "guster");
|
PatternType GUSTER = getType("guster");
|
||||||
|
|
||||||
private final String identifier;
|
|
||||||
private final NamespacedKey key;
|
|
||||||
private static final Map<String, PatternType> byString = new HashMap<String, PatternType>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
for (PatternType p : values()) {
|
|
||||||
byString.put(p.identifier, p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private PatternType(/*@NotNull*/ String identifier, String key) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
this.key = NamespacedKey.minecraft(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public NamespacedKey getKey() {
|
public NamespacedKey getKey();
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the identifier used to represent
|
* Returns the identifier used to represent
|
||||||
@@ -85,9 +70,7 @@ public enum PatternType implements Keyed {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
@Deprecated(forRemoval = true)
|
@Deprecated(forRemoval = true)
|
||||||
public String getIdentifier() {
|
public String getIdentifier();
|
||||||
return identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the pattern type which matches the passed
|
* Returns the pattern type which matches the passed
|
||||||
@@ -102,6 +85,48 @@ public enum PatternType implements Keyed {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Deprecated(forRemoval = true)
|
@Deprecated(forRemoval = true)
|
||||||
public static PatternType getByIdentifier(@Nullable String identifier) {
|
public static PatternType getByIdentifier(@Nullable String identifier) {
|
||||||
return byString.get(identifier);
|
if (identifier == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PatternType type : Registry.BANNER_PATTERN) {
|
||||||
|
if (identifier.equals(type.getIdentifier())) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static PatternType getType(@NotNull String key) {
|
||||||
|
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||||
|
PatternType type = Registry.BANNER_PATTERN.get(namespacedKey);
|
||||||
|
|
||||||
|
Preconditions.checkNotNull(type, "No Banner Pattern found for %s. This is a bug.", namespacedKey);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name of the pattern type.
|
||||||
|
* @return the pattern type with the given name.
|
||||||
|
* @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@Deprecated(since = "1.21")
|
||||||
|
static PatternType valueOf(@NotNull String name) {
|
||||||
|
PatternType type = Registry.BANNER_PATTERN.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
|
||||||
|
Preconditions.checkArgument(type != null, "No pattern type found with the name %s", name);
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an array of all known pattern types.
|
||||||
|
* @deprecated use {@link Registry#iterator()}.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@Deprecated(since = "1.21")
|
||||||
|
static PatternType[] values() {
|
||||||
|
return Lists.newArrayList(Registry.BANNER_PATTERN).toArray(new PatternType[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user