Don't convert legacy in register instead, only in required method

This commit is contained in:
DerFrZocker 2023-05-22 20:53:06 +02:00
parent 2200b334c7
commit e91906f511
No known key found for this signature in database
GPG key ID: 713F71FFFE1DDF91
5 changed files with 290 additions and 132 deletions

View file

@ -4,7 +4,10 @@ import com.google.common.collect.Multimap;
import org.bukkit.advancement.Advancement; import org.bukkit.advancement.Advancement;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier; import org.bukkit.attribute.AttributeModifier;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.CreativeCategory; import org.bukkit.inventory.CreativeCategory;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -87,4 +90,8 @@ public interface UnsafeValues {
String getItemTranslationKey(Material material); String getItemTranslationKey(Material material);
String getTranslationKey(ItemStack itemStack); String getTranslationKey(ItemStack itemStack);
EntityType<Entity> getUnkownEntityType();
Biome getCustomBiome();
} }

View file

@ -2,6 +2,7 @@ package org.bukkit.block;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.bukkit.Bukkit;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.MinecraftExperimental; import org.bukkit.MinecraftExperimental;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -91,7 +92,7 @@ public abstract class Biome extends OldEnum<Biome> implements Keyed {
* @deprecated only for backwards compatibility, custom is no longer returned. * @deprecated only for backwards compatibility, custom is no longer returned.
*/ */
@Deprecated @Deprecated
public static final Biome CUSTOM = getBiome("custom"); public static final Biome CUSTOM = Bukkit.getUnsafe().getCustomBiome();
@NotNull @NotNull
private static Biome getBiome(@NotNull String key) { private static Biome getBiome(@NotNull String key) {

View file

@ -323,7 +323,8 @@ public abstract class Enchantment implements Keyed {
if (name == null) { if (name == null) {
return null; return null;
} }
return getByKey(NamespacedKey.fromString(name)); name = convertLegacy(name);
return getByKey(NamespacedKey.fromString(name.toLowerCase()));
} }
/** /**
@ -366,4 +367,55 @@ public abstract class Enchantment implements Keyed {
*/ */
@Deprecated @Deprecated
public static void stopAcceptingRegistrations() {} public static void stopAcceptingRegistrations() {}
private static String convertLegacy(String from) {
if (from == null) {
return null;
}
switch (from.toLowerCase()) {
case "protection_environmental":
return "protection";
case "protection_fire":
return "fire_protection";
case "protection_fall":
return "feather_falling";
case "protection_explosions":
return "blast_protection";
case "protection_projectile":
return "projectile_protection";
case "oxygen":
return "respiration";
case "water_worker":
return "aqua_affinity";
case "damage_all":
return "sharpness";
case "damage_undead":
return "smite";
case "damage_arthropods":
return "bane_of_arthropods";
case "loot_bonus_mobs":
return "looting";
case "sweeping_edge":
return "sweeping";
case "dig_speed":
return "efficiency";
case "durability":
return "unbreaking";
case "loot_bonus_blocks":
return "fortune";
case "arrow_damage":
return "power";
case "arrow_knockback":
return "punch";
case "arrow_fire":
return "flame";
case "arrow_infinite":
return "infinity";
case "luck":
return "luck_of_the_sea";
}
return from;
}
} }

View file

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.bukkit.Bukkit;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.MinecraftExperimental; import org.bukkit.MinecraftExperimental;
@ -26,7 +27,7 @@ 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 abstract class EntityType extends OldEnum<EntityType> implements Keyed, Translatable { public abstract class EntityType<E extends Entity> extends OldEnum<EntityType<E>> implements Keyed, Translatable {
private static final BiMap<Short, EntityType> ID_MAP = HashBiMap.create(); private static final BiMap<Short, EntityType> ID_MAP = HashBiMap.create();
// These strings MUST match the strings in nms.EntityTypes and are case sensitive. // These strings MUST match the strings in nms.EntityTypes and are case sensitive.
@ -36,288 +37,290 @@ public abstract class EntityType extends OldEnum<EntityType> implements Keyed, T
* Spawn with {@link World#dropItem(Location, ItemStack)} or {@link * Spawn with {@link World#dropItem(Location, ItemStack)} or {@link
* World#dropItemNaturally(Location, ItemStack)} * World#dropItemNaturally(Location, ItemStack)}
*/ */
public static final EntityType ITEM = getEntityType("item", 1); public static final EntityType<Item> ITEM = getEntityType("item", 1);
/** /**
* An experience orb. * An experience orb.
*/ */
public static final EntityType EXPERIENCE_ORB = getEntityType("experience_orb", 2); public static final EntityType<ExperienceOrb> EXPERIENCE_ORB = getEntityType("experience_orb", 2);
/** /**
* @see AreaEffectCloud * @see AreaEffectCloud
*/ */
public static final EntityType AREA_EFFECT_CLOUD = getEntityType("area_effect_cloud", 3); public static final EntityType<AreaEffectCloud> AREA_EFFECT_CLOUD = getEntityType("area_effect_cloud", 3);
/** /**
* @see ElderGuardian * @see ElderGuardian
*/ */
public static final EntityType ELDER_GUARDIAN = getEntityType("elder_guardian", 4); public static final EntityType<ElderGuardian> ELDER_GUARDIAN = getEntityType("elder_guardian", 4);
/** /**
* @see WitherSkeleton * @see WitherSkeleton
*/ */
public static final EntityType WITHER_SKELETON = getEntityType("wither_skeleton", 5); public static final EntityType<WitherSkeleton> WITHER_SKELETON = getEntityType("wither_skeleton", 5);
/** /**
* @see Stray * @see Stray
*/ */
public static final EntityType STRAY = getEntityType("stray", 6); public static final EntityType<Stray> STRAY = getEntityType("stray", 6);
/** /**
* A flying chicken egg. * A flying chicken egg.
*/ */
public static final EntityType EGG = getEntityType("egg", 7); public static final EntityType<Egg> EGG = getEntityType("egg", 7);
/** /**
* A leash attached to a fencepost. * A leash attached to a fencepost.
*/ */
public static final EntityType LEASH_KNOT = getEntityType("leash_knot", 8); public static final EntityType<LeashHitch> LEASH_KNOT = getEntityType("leash_knot", 8);
/** /**
* A painting on a wall. * A painting on a wall.
*/ */
public static final EntityType PAINTING = getEntityType("painting", 9); public static final EntityType<Painting> PAINTING = getEntityType("painting", 9);
/** /**
* An arrow projectile; may get stuck in the ground. * An arrow projectile; may get stuck in the ground.
*/ */
public static final EntityType ARROW = getEntityType("arrow", 10); public static final EntityType<Arrow> ARROW = getEntityType("arrow", 10);
/** /**
* A flying snowball. * A flying snowball.
*/ */
public static final EntityType SNOWBALL = getEntityType("snowball", 11); public static final EntityType<Snowball> SNOWBALL = getEntityType("snowball", 11);
/** /**
* A flying large fireball, as thrown by a Ghast for example. * A flying large fireball, as thrown by a Ghast for example.
*/ */
public static final EntityType FIREBALL = getEntityType("fireball", 12); public static final EntityType<Fireball> FIREBALL = getEntityType("fireball", 12);
/** /**
* A flying small fireball, such as thrown by a Blaze or player. * A flying small fireball, such as thrown by a Blaze or player.
*/ */
public static final EntityType SMALL_FIREBALL = getEntityType("small_fireball", 13); public static final EntityType<SmallFireball> SMALL_FIREBALL = getEntityType("small_fireball", 13);
/** /**
* A flying ender pearl. * A flying ender pearl.
*/ */
public static final EntityType ENDER_PEARL = getEntityType("ender_pearl", 14); public static final EntityType<EnderPearl> ENDER_PEARL = getEntityType("ender_pearl", 14);
/** /**
* An ender eye signal. * An ender eye signal.
*/ */
public static final EntityType EYE_OF_ENDER = getEntityType("eye_of_ender", 15); public static final EntityType<EnderSignal> EYE_OF_ENDER = getEntityType("eye_of_ender", 15);
/** /**
* A flying splash potion. * A flying splash potion.
*/ */
public static final EntityType POTION = getEntityType("potion", 16); public static final EntityType<ThrownPotion> POTION = getEntityType("potion", 16);
/** /**
* A flying experience bottle. * A flying experience bottle.
*/ */
public static final EntityType EXPERIENCE_BOTTLE = getEntityType("experience_bottle", 17); public static final EntityType<ThrownExpBottle> EXPERIENCE_BOTTLE = getEntityType("experience_bottle", 17);
/** /**
* An item frame on a wall. * An item frame on a wall.
*/ */
public static final EntityType ITEM_FRAME = getEntityType("item_frame", 18); public static final EntityType<ItemFrame> ITEM_FRAME = getEntityType("item_frame", 18);
/** /**
* A flying wither skull projectile. * A flying wither skull projectile.
*/ */
public static final EntityType WITHER_SKULL = getEntityType("wither_skull", 19); public static final EntityType<WitherSkull> WITHER_SKULL = getEntityType("wither_skull", 19);
/** /**
* Primed TNT that is about to explode. * Primed TNT that is about to explode.
*/ */
public static final EntityType TNT = getEntityType("tnt", 20); public static final EntityType<TNTPrimed> TNT = getEntityType("tnt", 20);
/** /**
* A block that is going to or is about to fall. * A block that is going to or is about to fall.
*/ */
public static final EntityType FALLING_BLOCK = getEntityType("falling_block", 21); public static final EntityType<FallingBlock> FALLING_BLOCK = getEntityType("falling_block", 21);
/** /**
* Internal representation of a Firework once it has been launched. * Internal representation of a Firework once it has been launched.
*/ */
public static final EntityType FIREWORK_ROCKET = getEntityType("firework_rocket", 22); public static final EntityType<Firework> FIREWORK_ROCKET = getEntityType("firework_rocket", 22);
/** /**
* @see Husk * @see Husk
*/ */
public static final EntityType HUSK = getEntityType("husk", 23); public static final EntityType<Husk> HUSK = getEntityType("husk", 23);
/** /**
* Like {@link #ARROW} but causes the {@link PotionEffectType#GLOWING} effect on all team members. * Like {@link #ARROW} but causes the {@link PotionEffectType#GLOWING} effect on all team members.
*/ */
public static final EntityType SPECTRAL_ARROW = getEntityType("spectral_arrow", 24); public static final EntityType<SpectralArrow> SPECTRAL_ARROW = getEntityType("spectral_arrow", 24);
/** /**
* Bullet fired by {@link #SHULKER}. * Bullet fired by {@link #SHULKER}.
*/ */
public static final EntityType SHULKER_BULLET = getEntityType("shulker_bullet", 25); public static final EntityType<ShulkerBullet> SHULKER_BULLET = getEntityType("shulker_bullet", 25);
/** /**
* Like {@link #FIREBALL} but with added effects. * Like {@link #FIREBALL} but with added effects.
*/ */
public static final EntityType DRAGON_FIREBALL = getEntityType("dragon_fireball", 26); public static final EntityType<DragonFireball> DRAGON_FIREBALL = getEntityType("dragon_fireball", 26);
/** /**
* @see ZombieVillager * @see ZombieVillager
*/ */
public static final EntityType ZOMBIE_VILLAGER = getEntityType("zombie_villager", 27); public static final EntityType<ZombieVillager> ZOMBIE_VILLAGER = getEntityType("zombie_villager", 27);
/** /**
* @see SkeletonHorse * @see SkeletonHorse
*/ */
public static final EntityType SKELETON_HORSE = getEntityType("skeleton_horse", 28); public static final EntityType<SkeletonHorse> SKELETON_HORSE = getEntityType("skeleton_horse", 28);
/** /**
* @see ZombieHorse * @see ZombieHorse
*/ */
public static final EntityType ZOMBIE_HORSE = getEntityType("zombie_horse", 29); public static final EntityType<ZombieHorse> ZOMBIE_HORSE = getEntityType("zombie_horse", 29);
/** /**
* Mechanical entity with an inventory for placing weapons / armor into. * Mechanical entity with an inventory for placing weapons / armor into.
*/ */
public static final EntityType ARMOR_STAND = getEntityType("armor_stand", 30); public static final EntityType<ArmorStand> ARMOR_STAND = getEntityType("armor_stand", 30);
/** /**
* @see Donkey * @see Donkey
*/ */
public static final EntityType DONKEY = getEntityType("donkey", 31); public static final EntityType<Donkey> DONKEY = getEntityType("donkey", 31);
/** /**
* @see Mule * @see Mule
*/ */
public static final EntityType MULE = getEntityType("mule", 32); public static final EntityType<Mule> MULE = getEntityType("mule", 32);
/** /**
* @see EvokerFangs * @see EvokerFangs
*/ */
public static final EntityType EVOKER_FANGS = getEntityType("evoker_fangs", 33); public static final EntityType<EvokerFangs> EVOKER_FANGS = getEntityType("evoker_fangs", 33);
/** /**
* @see Evoker * @see Evoker
*/ */
public static final EntityType EVOKER = getEntityType("evoker", 34); public static final EntityType<Evoker> EVOKER = getEntityType("evoker", 34);
/** /**
* @see Vex * @see Vex
*/ */
public static final EntityType VEX = getEntityType("vex", 35); public static final EntityType<Vex> VEX = getEntityType("vex", 35);
/** /**
* @see Vindicator * @see Vindicator
*/ */
public static final EntityType VINDICATOR = getEntityType("vindicator", 36); public static final EntityType<Vindicator> VINDICATOR = getEntityType("vindicator", 36);
/** /**
* @see Illusioner * @see Illusioner
*/ */
public static final EntityType ILLUSIONER = getEntityType("illusioner", 37); public static final EntityType<Illusioner> ILLUSIONER = getEntityType("illusioner", 37);
/** /**
* @see CommandMinecart * @see CommandMinecart
*/ */
public static final EntityType COMMAND_BLOCK_MINECART = getEntityType("command_block_minecart", 40); public static final EntityType<CommandMinecart> COMMAND_BLOCK_MINECART = getEntityType("command_block_minecart", 40);
/** /**
* A placed boat. * A placed boat.
*/ */
public static final EntityType BOAT = getEntityType("boat", 41); public static final EntityType<Boat> BOAT = getEntityType("boat", 41);
/** /**
* @see RideableMinecart * @see RideableMinecart
*/ */
public static final EntityType MINECART = getEntityType("minecart", 42); public static final EntityType<RideableMinecart> MINECART = getEntityType("minecart", 42);
/** /**
* @see StorageMinecart * @see StorageMinecart
*/ */
public static final EntityType CHEST_MINECART = getEntityType("chest_minecart", 43); public static final EntityType<StorageMinecart> CHEST_MINECART = getEntityType("chest_minecart", 43);
/** /**
* @see PoweredMinecart * @see PoweredMinecart
*/ */
public static final EntityType FURNACE_MINECART = getEntityType("furnace_minecart", 44); public static final EntityType<PoweredMinecart> FURNACE_MINECART = getEntityType("furnace_minecart", 44);
/** /**
* @see ExplosiveMinecart * @see ExplosiveMinecart
*/ */
public static final EntityType TNT_MINECART = getEntityType("tnt_minecart", 45); public static final EntityType<ExplosiveMinecart> TNT_MINECART = getEntityType("tnt_minecart", 45);
/** /**
* @see HopperMinecart * @see HopperMinecart
*/ */
public static final EntityType HOPPER_MINECART = getEntityType("hopper_minecart", 46); public static final EntityType<HopperMinecart> HOPPER_MINECART = getEntityType("hopper_minecart", 46);
/** /**
* @see SpawnerMinecart * @see SpawnerMinecart
*/ */
public static final EntityType SPAWNER_MINECART = getEntityType("spawner_minecart", 47); public static final EntityType<SpawnerMinecart> SPAWNER_MINECART = getEntityType("spawner_minecart", 47);
public static final EntityType CREEPER = getEntityType("creeper", 50); public static final EntityType<Creeper> CREEPER = getEntityType("creeper", 50);
public static final EntityType SKELETON = getEntityType("skeleton", 51); public static final EntityType<Skeleton> SKELETON = getEntityType("skeleton", 51);
public static final EntityType SPIDER = getEntityType("spider", 52); public static final EntityType<Spider> SPIDER = getEntityType("spider", 52);
public static final EntityType GIANT = getEntityType("giant", 53); public static final EntityType<Giant> GIANT = getEntityType("giant", 53);
public static final EntityType ZOMBIE = getEntityType("zombie", 54); public static final EntityType<Zombie> ZOMBIE = getEntityType("zombie", 54);
public static final EntityType SLIME = getEntityType("slime", 55); public static final EntityType<Slime> SLIME = getEntityType("slime", 55);
public static final EntityType GHAST = getEntityType("ghast", 56); public static final EntityType<Ghast> GHAST = getEntityType("ghast", 56);
public static final EntityType ZOMBIFIED_PIGLIN = getEntityType("zombified_piglin", 57); public static final EntityType<PigZombie> ZOMBIFIED_PIGLIN = getEntityType("zombified_piglin", 57);
public static final EntityType ENDERMAN = getEntityType("enderman", 58); public static final EntityType<Enderman> ENDERMAN = getEntityType("enderman", 58);
public static final EntityType CAVE_SPIDER = getEntityType("cave_spider", 59); public static final EntityType<CaveSpider> CAVE_SPIDER = getEntityType("cave_spider", 59);
public static final EntityType SILVERFISH = getEntityType("silverfish", 60); public static final EntityType<Silverfish> SILVERFISH = getEntityType("silverfish", 60);
public static final EntityType BLAZE = getEntityType("blaze", 61); public static final EntityType<Blaze> BLAZE = getEntityType("blaze", 61);
public static final EntityType MAGMA_CUBE = getEntityType("magma_cube", 62); public static final EntityType<MagmaCube> MAGMA_CUBE = getEntityType("magma_cube", 62);
public static final EntityType ENDER_DRAGON = getEntityType("ender_dragon", 63); public static final EntityType<EnderDragon> ENDER_DRAGON = getEntityType("ender_dragon", 63);
public static final EntityType WITHER = getEntityType("wither", 64); public static final EntityType<Wither> WITHER = getEntityType("wither", 64);
public static final EntityType BAT = getEntityType("bat", 65); public static final EntityType<Bat> BAT = getEntityType("bat", 65);
public static final EntityType WITCH = getEntityType("witch", 66); public static final EntityType<Witch> WITCH = getEntityType("witch", 66);
public static final EntityType ENDERMITE = getEntityType("endermite", 67); public static final EntityType<Endermite> ENDERMITE = getEntityType("endermite", 67);
public static final EntityType GUARDIAN = getEntityType("guardian", 68); public static final EntityType<Guardian> GUARDIAN = getEntityType("guardian", 68);
public static final EntityType SHULKER = getEntityType("shulker", 69); public static final EntityType<Shulker> SHULKER = getEntityType("shulker", 69);
public static final EntityType PIG = getEntityType("pig", 90); public static final EntityType<Pig> PIG = getEntityType("pig", 90);
public static final EntityType SHEEP = getEntityType("sheep", 91); public static final EntityType<Sheep> SHEEP = getEntityType("sheep", 91);
public static final EntityType COW = getEntityType("cow", 92); public static final EntityType<Cow> COW = getEntityType("cow", 92);
public static final EntityType CHICKEN = getEntityType("chicken", 93); public static final EntityType<Chicken> CHICKEN = getEntityType("chicken", 93);
public static final EntityType SQUID = getEntityType("squid", 94); public static final EntityType<Squid> SQUID = getEntityType("squid", 94);
public static final EntityType WOLF = getEntityType("wolf", 95); public static final EntityType<Wolf> WOLF = getEntityType("wolf", 95);
public static final EntityType MOOSHROOM = getEntityType("mooshroom", 96); public static final EntityType<MushroomCow> MOOSHROOM = getEntityType("mooshroom", 96);
public static final EntityType SNOW_GOLEM = getEntityType("snow_golem", 97); public static final EntityType<Snowman> SNOW_GOLEM = getEntityType("snow_golem", 97);
public static final EntityType OCELOT = getEntityType("ocelot", 98); public static final EntityType<Ocelot> OCELOT = getEntityType("ocelot", 98);
public static final EntityType IRON_GOLEM = getEntityType("iron_golem", 99); public static final EntityType<IronGolem> IRON_GOLEM = getEntityType("iron_golem", 99);
public static final EntityType HORSE = getEntityType("horse", 100); public static final EntityType<Horse> HORSE = getEntityType("horse", 100);
public static final EntityType RABBIT = getEntityType("rabbit", 101); public static final EntityType<Rabbit> RABBIT = getEntityType("rabbit", 101);
public static final EntityType POLAR_BEAR = getEntityType("polar_bear", 102); public static final EntityType<PolarBear> POLAR_BEAR = getEntityType("polar_bear", 102);
public static final EntityType LLAMA = getEntityType("llama", 103); public static final EntityType<Llama> LLAMA = getEntityType("llama", 103);
public static final EntityType LLAMA_SPIT = getEntityType("llama_spit", 104); public static final EntityType<LlamaSpit> LLAMA_SPIT = getEntityType("llama_spit", 104);
public static final EntityType PARROT = getEntityType("parrot", 105); public static final EntityType<Parrot> PARROT = getEntityType("parrot", 105);
public static final EntityType VILLAGER = getEntityType("villager", 120); public static final EntityType<Villager> VILLAGER = getEntityType("villager", 120);
public static final EntityType END_CRYSTAL = getEntityType("end_crystal", 200); public static final EntityType<EnderCrystal> END_CRYSTAL = getEntityType("end_crystal", 200);
public static final EntityType TURTLE = getEntityType("turtle"); public static final EntityType<Turtle> TURTLE = getEntityType("turtle");
public static final EntityType PHANTOM = getEntityType("phantom"); public static final EntityType<Phantom> PHANTOM = getEntityType("phantom");
public static final EntityType TRIDENT = getEntityType("trident"); public static final EntityType<Trident> TRIDENT = getEntityType("trident");
public static final EntityType COD = getEntityType("cod"); public static final EntityType<Cod> COD = getEntityType("cod");
public static final EntityType SALMON = getEntityType("salmon"); public static final EntityType<Salmon> SALMON = getEntityType("salmon");
public static final EntityType PUFFERFISH = getEntityType("pufferfish"); public static final EntityType<PufferFish> PUFFERFISH = getEntityType("pufferfish");
public static final EntityType TROPICAL_FISH = getEntityType("tropical_fish"); public static final EntityType<TropicalFish> TROPICAL_FISH = getEntityType("tropical_fish");
public static final EntityType DROWNED = getEntityType("drowned"); public static final EntityType<Drowned> DROWNED = getEntityType("drowned");
public static final EntityType DOLPHIN = getEntityType("dolphin"); public static final EntityType<Dolphin> DOLPHIN = getEntityType("dolphin");
public static final EntityType CAT = getEntityType("cat"); public static final EntityType<Cat> CAT = getEntityType("cat");
public static final EntityType PANDA = getEntityType("panda"); public static final EntityType<Panda> PANDA = getEntityType("panda");
public static final EntityType PILLAGER = getEntityType("pillager"); public static final EntityType<Pillager> PILLAGER = getEntityType("pillager");
public static final EntityType RAVAGER = getEntityType("ravager"); public static final EntityType<Ravager> RAVAGER = getEntityType("ravager");
public static final EntityType TRADER_LLAMA = getEntityType("trader_llama"); public static final EntityType<TraderLlama> TRADER_LLAMA = getEntityType("trader_llama");
public static final EntityType WANDERING_TRADER = getEntityType("wandering_trader"); public static final EntityType<WanderingTrader> WANDERING_TRADER = getEntityType("wandering_trader");
public static final EntityType FOX = getEntityType("fox"); public static final EntityType<Fox> FOX = getEntityType("fox");
public static final EntityType BEE = getEntityType("bee"); public static final EntityType<Bee> BEE = getEntityType("bee");
public static final EntityType HOGLIN = getEntityType("hoglin"); public static final EntityType<Hoglin> HOGLIN = getEntityType("hoglin");
public static final EntityType PIGLIN = getEntityType("piglin"); public static final EntityType<Piglin> PIGLIN = getEntityType("piglin");
public static final EntityType STRIDER = getEntityType("strider"); public static final EntityType<Strider> STRIDER = getEntityType("strider");
public static final EntityType ZOGLIN = getEntityType("zoglin"); public static final EntityType<Zoglin> ZOGLIN = getEntityType("zoglin");
public static final EntityType PIGLIN_BRUTE = getEntityType("piglin_brute"); public static final EntityType<PiglinBrute> PIGLIN_BRUTE = getEntityType("piglin_brute");
public static final EntityType AXOLOTL = getEntityType("axolotl"); public static final EntityType<Axolotl> AXOLOTL = getEntityType("axolotl");
public static final EntityType GLOW_ITEM_FRAME = getEntityType("glow_item_frame"); public static final EntityType<GlowItemFrame> GLOW_ITEM_FRAME = getEntityType("glow_item_frame");
public static final EntityType GLOW_SQUID = getEntityType("glow_squid"); public static final EntityType<GlowSquid> GLOW_SQUID = getEntityType("glow_squid");
public static final EntityType GOAT = getEntityType("goat"); public static final EntityType<Goat> GOAT = getEntityType("goat");
public static final EntityType MARKER = getEntityType("marker"); public static final EntityType<Marker> MARKER = getEntityType("marker");
public static final EntityType ALLAY = getEntityType("allay"); public static final EntityType<Allay> ALLAY = getEntityType("allay");
public static final EntityType CHEST_BOAT = getEntityType("chest_boat"); public static final EntityType<ChestBoat> CHEST_BOAT = getEntityType("chest_boat");
public static final EntityType FROG = getEntityType("frog"); public static final EntityType<Frog> FROG = getEntityType("frog");
public static final EntityType TADPOLE = getEntityType("tadpole"); public static final EntityType<Tadpole> TADPOLE = getEntityType("tadpole");
public static final EntityType WARDEN = getEntityType("warden"); public static final EntityType<Warden> WARDEN = getEntityType("warden");
@MinecraftExperimental @MinecraftExperimental
@ApiStatus.Experimental @ApiStatus.Experimental
public static final EntityType CAMEL = getEntityType("camel"); public static final EntityType<Camel> CAMEL = getEntityType("camel");
public static final EntityType BLOCK_DISPLAY = getEntityType("block_display"); public static final EntityType<BlockDisplay> BLOCK_DISPLAY = getEntityType("block_display");
public static final EntityType INTERACTION = getEntityType("interaction"); public static final EntityType<Interaction> INTERACTION = getEntityType("interaction");
public static final EntityType ITEM_DISPLAY = getEntityType("item_display"); public static final EntityType<ItemDisplay> ITEM_DISPLAY = getEntityType("item_display");
@MinecraftExperimental @MinecraftExperimental
@ApiStatus.Experimental @ApiStatus.Experimental
public static final EntityType SNIFFER = getEntityType("sniffer"); public static final EntityType<Sniffer> SNIFFER = getEntityType("sniffer");
public static final EntityType TEXT_DISPLAY = getEntityType("text_display"); public static final EntityType<TextDisplay> TEXT_DISPLAY = getEntityType("text_display");
/** /**
* A fishing line and bobber. * A fishing line and bobber.
*/ */
public static final EntityType FISHING_BOBBER = getEntityType("fishing_bobber"); public static final EntityType<FishHook> FISHING_BOBBER = getEntityType("fishing_bobber");
/** /**
* A bolt of lightning. * A bolt of lightning.
* <p> * <p>
* Spawn with {@link World#strikeLightning(Location)}. * Spawn with {@link World#strikeLightning(Location)}.
*/ */
public static final EntityType LIGHTNING_BOLT = getEntityType("lightning_bolt"); public static final EntityType<LightningStrike> LIGHTNING_BOLT = getEntityType("lightning_bolt");
public static final EntityType PLAYER = getEntityType("player"); public static final EntityType<Player> PLAYER = getEntityType("player");
/** /**
* An unknown entity without an Entity Class * An unknown entity without an Entity Class
* @deprecated only for backwards compatibility, unknown is no longer returned. * @deprecated only for backwards compatibility, unknown is no longer returned.
*/ */
@Deprecated @Deprecated
public static final EntityType UNKNOWN = getEntityType("unknown"); public static final EntityType<Entity> UNKNOWN = Bukkit.getUnsafe().getUnkownEntityType();
private static EntityType getEntityType(@NotNull String key) { @NotNull
private static <E extends Entity> EntityType<E> getEntityType(@NotNull String key) {
return getEntityType(key, -1); return getEntityType(key, -1);
} }
private static EntityType getEntityType(@NotNull String key, int typeId) { @NotNull
private static <E extends Entity> EntityType<E> getEntityType(@NotNull String key, int typeId) {
NamespacedKey namespacedKey = NamespacedKey.minecraft(key); NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
EntityType entityType = Registry.ENTITY_TYPE.get(namespacedKey); EntityType<E> entityType = (EntityType<E>) Registry.ENTITY_TYPE.get(namespacedKey);
Preconditions.checkNotNull(entityType, "No EntityType found for %s. This is a bug.", namespacedKey); Preconditions.checkNotNull(entityType, "No EntityType found for %s. This is a bug.", namespacedKey);
if (typeId > 0) { if (typeId > 0) {
ID_MAP.put((short) typeId, entityType); ID_MAP.put((short) typeId, entityType);
@ -338,7 +341,7 @@ public abstract class EntityType extends OldEnum<EntityType> implements Keyed, T
public abstract boolean isAlive(); public abstract boolean isAlive();
@Nullable @Nullable
public abstract Class<? extends Entity> getEntityClass(); public abstract Class<E> getEntityClass();
/** /**
* Gets the entity type name. * Gets the entity type name.
@ -375,6 +378,7 @@ public abstract class EntityType extends OldEnum<EntityType> implements Keyed, T
if (name == null) { if (name == null) {
return null; return null;
} }
name = convertLegacy(name);
return Registry.ENTITY_TYPE.get(NamespacedKey.fromString(name.toLowerCase(java.util.Locale.ENGLISH))); return Registry.ENTITY_TYPE.get(NamespacedKey.fromString(name.toLowerCase(java.util.Locale.ENGLISH)));
} }
@ -402,6 +406,7 @@ public abstract class EntityType extends OldEnum<EntityType> implements Keyed, T
@NotNull @NotNull
@Deprecated @Deprecated
public static EntityType valueOf(@NotNull String name) { public static EntityType valueOf(@NotNull String name) {
name = convertLegacy(name);
EntityType entityType = Registry.ENTITY_TYPE.get(NamespacedKey.fromString(name.toLowerCase())); EntityType entityType = Registry.ENTITY_TYPE.get(NamespacedKey.fromString(name.toLowerCase()));
Preconditions.checkArgument(entityType != null, "No EntityType found with the name %s", name); Preconditions.checkArgument(entityType != null, "No EntityType found with the name %s", name);
return entityType; return entityType;
@ -416,4 +421,67 @@ public abstract class EntityType extends OldEnum<EntityType> implements Keyed, T
public static EntityType[] values() { public static EntityType[] values() {
return Lists.newArrayList(Registry.ENTITY_TYPE).toArray(new EntityType[0]); return Lists.newArrayList(Registry.ENTITY_TYPE).toArray(new EntityType[0]);
} }
private static String convertLegacy(String from) {
if (from == null) {
return null;
}
switch (from.toLowerCase()) {
case "xp_orb":
return "experience_orb";
case "eye_of_ender_signal":
case "ender_signal":
return "eye_of_ender";
case "xp_boottle":
case "thrown_exp_bottle":
return "experience_bottle";
case "fireworks_rocket":
case "firework":
return "firework_rocket";
case "evocation_fangs":
return "evoker_fangs";
case "evocation_illager":
return "evoker";
case "vindication_illager":
return "vindicator";
case "illusion_illager":
return "illusioner";
case "commandblock_minecart":
case "minecart_command":
return "command_block_minecart";
case "snowman":
return "snow_golem";
case "villager_golem":
return "iron_golem";
case "ender_crystal":
return "end_crystal";
case "dropped_item":
return "item";
case "leash_hitch":
return "leash_knot";
case "splash_potion":
return "potion";
case "primed_tnt":
return "tnt";
case "minecart_chest":
return "chest_minecart";
case "minecart_furnace":
return "furnace_minecart";
case "minecart_tnt":
return "tnt_minecart";
case "minecart_hopper":
return "hopper_minecart";
case "minecart_mob_spawner":
return "spawner_minecart";
case "mushroom_cow":
return "mooshroom";
case "fishing_hook":
return "fishing_bobber";
case "lightning":
return "lightning_bolt";
}
return from;
}
} }

View file

@ -290,6 +290,7 @@ public abstract class PotionEffectType implements Keyed {
@Deprecated @Deprecated
public static PotionEffectType getByName(@NotNull String name) { public static PotionEffectType getByName(@NotNull String name) {
Preconditions.checkArgument(name != null, "name cannot be null"); Preconditions.checkArgument(name != null, "name cannot be null");
name = convertLegacy(name);
return Registry.POTION_EFFECT_TYPE.get(NamespacedKey.fromString(name.toLowerCase(java.util.Locale.ENGLISH))); return Registry.POTION_EFFECT_TYPE.get(NamespacedKey.fromString(name.toLowerCase(java.util.Locale.ENGLISH)));
} }
@ -320,4 +321,33 @@ public abstract class PotionEffectType implements Keyed {
*/ */
@Deprecated @Deprecated
public static void stopAcceptingRegistrations() {} public static void stopAcceptingRegistrations() {}
private static String convertLegacy(String from) {
if (from == null) {
return null;
}
switch (from.toLowerCase()) {
case "slow":
return "slowness";
case "fast_digging":
return "haste";
case "slow_digging":
return "mining_fatigue";
case "increase_damage":
return "strength";
case "heal":
return "instant_health";
case "harm":
return "instant_damage";
case "jump":
return "jump_boost";
case "confusion":
return "nausea";
case "damage_resistance":
return "resistance";
}
return from;
}
} }