13
0
geforkt von Mirrors/Paper

#940: Create registry for banner pattern and cat type

By: Jishuna <joshl5324@gmail.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2023-12-08 19:24:14 +11:00
Ursprung 0c336e76ce
Commit 460ea2aff9
3 geänderte Dateien mit 101 neuen und 56 gelöschten Zeilen

Datei anzeigen

@ -12,8 +12,10 @@ import java.util.stream.StreamSupport;
import org.bukkit.advancement.Advancement; import org.bukkit.advancement.Advancement;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.banner.PatternType;
import org.bukkit.boss.KeyedBossBar; import org.bukkit.boss.KeyedBossBar;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Cat;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Frog; import org.bukkit.entity.Frog;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
@ -75,6 +77,12 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
* @see Attribute * @see Attribute
*/ */
Registry<Attribute> ATTRIBUTE = new SimpleRegistry<>(Attribute.class); Registry<Attribute> ATTRIBUTE = new SimpleRegistry<>(Attribute.class);
/**
* Server banner patterns.
*
* @see PatternType
*/
Registry<PatternType> BANNER_PATTERN = new SimpleRegistry<>(PatternType.class);
/** /**
* Server biomes. * Server biomes.
* *
@ -107,6 +115,12 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
return Bukkit.getBossBars(); return Bukkit.getBossBars();
} }
}; };
/**
* Server cat types.
*
* @see Cat.Type
*/
Registry<Cat.Type> CAT_VARIANT = new SimpleRegistry<>(Cat.Type.class);
/** /**
* Server enchantments. * Server enchantments.
* *

Datei anzeigen

@ -2,54 +2,58 @@ package org.bukkit.block.banner;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
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 { public enum PatternType implements Keyed {
BASE("b"), BASE("b", "base"),
SQUARE_BOTTOM_LEFT("bl"), SQUARE_BOTTOM_LEFT("bl", "square_bottom_left"),
SQUARE_BOTTOM_RIGHT("br"), SQUARE_BOTTOM_RIGHT("br", "square_bottom_right"),
SQUARE_TOP_LEFT("tl"), SQUARE_TOP_LEFT("tl", "square_top_left"),
SQUARE_TOP_RIGHT("tr"), SQUARE_TOP_RIGHT("tr", "square_top_right"),
STRIPE_BOTTOM("bs"), STRIPE_BOTTOM("bs", "stripe_bottom"),
STRIPE_TOP("ts"), STRIPE_TOP("ts", "stripe_top"),
STRIPE_LEFT("ls"), STRIPE_LEFT("ls", "stripe_left"),
STRIPE_RIGHT("rs"), STRIPE_RIGHT("rs", "stripe_right"),
STRIPE_CENTER("cs"), STRIPE_CENTER("cs", "stripe_center"),
STRIPE_MIDDLE("ms"), STRIPE_MIDDLE("ms", "stripe_middle"),
STRIPE_DOWNRIGHT("drs"), STRIPE_DOWNRIGHT("drs", "stripe_downright"),
STRIPE_DOWNLEFT("dls"), STRIPE_DOWNLEFT("dls", "stripe_downleft"),
STRIPE_SMALL("ss"), STRIPE_SMALL("ss", "small_stripes"),
CROSS("cr"), CROSS("cr", "cross"),
STRAIGHT_CROSS("sc"), STRAIGHT_CROSS("sc", "straight_cross"),
TRIANGLE_BOTTOM("bt"), TRIANGLE_BOTTOM("bt", "triangle_bottom"),
TRIANGLE_TOP("tt"), TRIANGLE_TOP("tt", "triangle_top"),
TRIANGLES_BOTTOM("bts"), TRIANGLES_BOTTOM("bts", "triangles_bottom"),
TRIANGLES_TOP("tts"), TRIANGLES_TOP("tts", "triangles_top"),
DIAGONAL_LEFT("ld"), DIAGONAL_LEFT("ld", "diagonal_left"),
DIAGONAL_RIGHT("rd"), DIAGONAL_RIGHT("rd", "diagonal_up_right"), //PAIL - Why are these keys swapped?
DIAGONAL_LEFT_MIRROR("lud"), DIAGONAL_LEFT_MIRROR("lud", "diagonal_up_left"),
DIAGONAL_RIGHT_MIRROR("rud"), DIAGONAL_RIGHT_MIRROR("rud", "diagonal_right"), //PAIL - Why are these keys swapped?
CIRCLE_MIDDLE("mc"), CIRCLE_MIDDLE("mc", "circle"),
RHOMBUS_MIDDLE("mr"), RHOMBUS_MIDDLE("mr", "rhombus"),
HALF_VERTICAL("vh"), HALF_VERTICAL("vh", "half_vertical"),
HALF_HORIZONTAL("hh"), HALF_HORIZONTAL("hh", "half_horizontal"),
HALF_VERTICAL_MIRROR("vhr"), HALF_VERTICAL_MIRROR("vhr", "half_vertical_right"),
HALF_HORIZONTAL_MIRROR("hhb"), HALF_HORIZONTAL_MIRROR("hhb", "half_horizontal_bottom"),
BORDER("bo"), BORDER("bo", "border"),
CURLY_BORDER("cbo"), CURLY_BORDER("cbo", "curly_border"),
CREEPER("cre"), CREEPER("cre", "creeper"),
GRADIENT("gra"), GRADIENT("gra", "gradient"),
GRADIENT_UP("gru"), GRADIENT_UP("gru", "gradient_up"),
BRICKS("bri"), BRICKS("bri", "bricks"),
SKULL("sku"), SKULL("sku", "skull"),
FLOWER("flo"), FLOWER("flo", "flower"),
MOJANG("moj"), MOJANG("moj", "mojang"),
GLOBE("glb"), GLOBE("glb", "globe"),
PIGLIN("pig"); PIGLIN("pig", "piglin");
private final String identifier; private final String identifier;
private final NamespacedKey key;
private static final Map<String, PatternType> byString = new HashMap<String, PatternType>(); private static final Map<String, PatternType> byString = new HashMap<String, PatternType>();
static { static {
@ -58,8 +62,15 @@ public enum PatternType {
} }
} }
private PatternType(/*@NotNull*/ String key) { private PatternType(/*@NotNull*/ String identifier, String key) {
this.identifier = key; this.identifier = identifier;
this.key = NamespacedKey.minecraft(key);
}
@Override
@NotNull
public NamespacedKey getKey() {
return key;
} }
/** /**
@ -67,8 +78,11 @@ public enum PatternType {
* this pattern type * this pattern type
* *
* @return the pattern's identifier * @return the pattern's identifier
* @see #getKey
* @deprecated magic value
*/ */
@NotNull @NotNull
@Deprecated
public String getIdentifier() { public String getIdentifier() {
return identifier; return identifier;
} }
@ -79,9 +93,12 @@ public enum PatternType {
* *
* @param identifier the identifier * @param identifier the identifier
* @return the matched pattern type or null * @return the matched pattern type or null
* @see Registry#BANNER_PATTERN
* @deprecated magic value, use {@link Registry#get(NamespacedKey)} instead
*/ */
@Contract("null -> null") @Contract("null -> null")
@Nullable @Nullable
@Deprecated
public static PatternType getByIdentifier(@Nullable String identifier) { public static PatternType getByIdentifier(@Nullable String identifier) {
return byString.get(identifier); return byString.get(identifier);
} }

Datei anzeigen

@ -1,6 +1,8 @@
package org.bukkit.entity; package org.bukkit.entity;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
@ -41,17 +43,29 @@ public interface Cat extends Tameable, Sittable {
/** /**
* Represents the various different cat types there are. * Represents the various different cat types there are.
*/ */
public enum Type { public enum Type implements Keyed {
TABBY, TABBY("tabby"),
BLACK, BLACK("black"),
RED, RED("red"),
SIAMESE, SIAMESE("siamese"),
BRITISH_SHORTHAIR, BRITISH_SHORTHAIR("british_shorthair"),
CALICO, CALICO("calico"),
PERSIAN, PERSIAN("persian"),
RAGDOLL, RAGDOLL("ragdoll"),
WHITE, WHITE("white"),
JELLIE, JELLIE("jellie"),
ALL_BLACK; ALL_BLACK("all_black");
private final NamespacedKey key;
private Type(String key) {
this.key = NamespacedKey.minecraft(key);
}
@Override
@NotNull
public NamespacedKey getKey() {
return key;
}
} }
} }