From e91906f5118ca6c644233768d4f8a701524fb30c Mon Sep 17 00:00:00 2001 From: DerFrZocker Date: Mon, 22 May 2023 20:53:06 +0200 Subject: [PATCH] Don't convert legacy in register instead, only in required method --- src/main/java/org/bukkit/UnsafeValues.java | 7 + src/main/java/org/bukkit/block/Biome.java | 3 +- .../org/bukkit/enchantments/Enchantment.java | 54 ++- .../java/org/bukkit/entity/EntityType.java | 328 +++++++++++------- .../org/bukkit/potion/PotionEffectType.java | 30 ++ 5 files changed, 290 insertions(+), 132 deletions(-) diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java index c89586b7..86eb492d 100644 --- a/src/main/java/org/bukkit/UnsafeValues.java +++ b/src/main/java/org/bukkit/UnsafeValues.java @@ -4,7 +4,10 @@ import com.google.common.collect.Multimap; import org.bukkit.advancement.Advancement; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; +import org.bukkit.block.Biome; 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.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -87,4 +90,8 @@ public interface UnsafeValues { String getItemTranslationKey(Material material); String getTranslationKey(ItemStack itemStack); + + EntityType getUnkownEntityType(); + + Biome getCustomBiome(); } diff --git a/src/main/java/org/bukkit/block/Biome.java b/src/main/java/org/bukkit/block/Biome.java index e9e350d7..66d93bc4 100644 --- a/src/main/java/org/bukkit/block/Biome.java +++ b/src/main/java/org/bukkit/block/Biome.java @@ -2,6 +2,7 @@ package org.bukkit.block; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; +import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.MinecraftExperimental; import org.bukkit.NamespacedKey; @@ -91,7 +92,7 @@ public abstract class Biome extends OldEnum implements Keyed { * @deprecated only for backwards compatibility, custom is no longer returned. */ @Deprecated - public static final Biome CUSTOM = getBiome("custom"); + public static final Biome CUSTOM = Bukkit.getUnsafe().getCustomBiome(); @NotNull private static Biome getBiome(@NotNull String key) { diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java index 36f9410e..8ecafe5d 100644 --- a/src/main/java/org/bukkit/enchantments/Enchantment.java +++ b/src/main/java/org/bukkit/enchantments/Enchantment.java @@ -323,7 +323,8 @@ public abstract class Enchantment implements Keyed { if (name == 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 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; + } } diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java index 39252d76..b13740d4 100644 --- a/src/main/java/org/bukkit/entity/EntityType.java +++ b/src/main/java/org/bukkit/entity/EntityType.java @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Lists; +import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.Location; import org.bukkit.MinecraftExperimental; @@ -26,7 +27,7 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public abstract class EntityType extends OldEnum implements Keyed, Translatable { +public abstract class EntityType extends OldEnum> implements Keyed, Translatable { private static final BiMap ID_MAP = HashBiMap.create(); // These strings MUST match the strings in nms.EntityTypes and are case sensitive. @@ -36,288 +37,290 @@ public abstract class EntityType extends OldEnum implements Keyed, T * Spawn with {@link World#dropItem(Location, ItemStack)} or {@link * World#dropItemNaturally(Location, ItemStack)} */ - public static final EntityType ITEM = getEntityType("item", 1); + public static final EntityType ITEM = getEntityType("item", 1); /** * An experience orb. */ - public static final EntityType EXPERIENCE_ORB = getEntityType("experience_orb", 2); + public static final EntityType EXPERIENCE_ORB = getEntityType("experience_orb", 2); /** * @see AreaEffectCloud */ - public static final EntityType AREA_EFFECT_CLOUD = getEntityType("area_effect_cloud", 3); + public static final EntityType AREA_EFFECT_CLOUD = getEntityType("area_effect_cloud", 3); /** * @see ElderGuardian */ - public static final EntityType ELDER_GUARDIAN = getEntityType("elder_guardian", 4); + public static final EntityType ELDER_GUARDIAN = getEntityType("elder_guardian", 4); /** * @see WitherSkeleton */ - public static final EntityType WITHER_SKELETON = getEntityType("wither_skeleton", 5); + public static final EntityType WITHER_SKELETON = getEntityType("wither_skeleton", 5); /** * @see Stray */ - public static final EntityType STRAY = getEntityType("stray", 6); + public static final EntityType STRAY = getEntityType("stray", 6); /** * A flying chicken egg. */ - public static final EntityType EGG = getEntityType("egg", 7); + public static final EntityType EGG = getEntityType("egg", 7); /** * A leash attached to a fencepost. */ - public static final EntityType LEASH_KNOT = getEntityType("leash_knot", 8); + public static final EntityType LEASH_KNOT = getEntityType("leash_knot", 8); /** * A painting on a wall. */ - public static final EntityType PAINTING = getEntityType("painting", 9); + public static final EntityType PAINTING = getEntityType("painting", 9); /** * An arrow projectile; may get stuck in the ground. */ - public static final EntityType ARROW = getEntityType("arrow", 10); + public static final EntityType ARROW = getEntityType("arrow", 10); /** * A flying snowball. */ - public static final EntityType SNOWBALL = getEntityType("snowball", 11); + public static final EntityType SNOWBALL = getEntityType("snowball", 11); /** * A flying large fireball, as thrown by a Ghast for example. */ - public static final EntityType FIREBALL = getEntityType("fireball", 12); + public static final EntityType FIREBALL = getEntityType("fireball", 12); /** * 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 SMALL_FIREBALL = getEntityType("small_fireball", 13); /** * A flying ender pearl. */ - public static final EntityType ENDER_PEARL = getEntityType("ender_pearl", 14); + public static final EntityType ENDER_PEARL = getEntityType("ender_pearl", 14); /** * An ender eye signal. */ - public static final EntityType EYE_OF_ENDER = getEntityType("eye_of_ender", 15); + public static final EntityType EYE_OF_ENDER = getEntityType("eye_of_ender", 15); /** * A flying splash potion. */ - public static final EntityType POTION = getEntityType("potion", 16); + public static final EntityType POTION = getEntityType("potion", 16); /** * A flying experience bottle. */ - public static final EntityType EXPERIENCE_BOTTLE = getEntityType("experience_bottle", 17); + public static final EntityType EXPERIENCE_BOTTLE = getEntityType("experience_bottle", 17); /** * An item frame on a wall. */ - public static final EntityType ITEM_FRAME = getEntityType("item_frame", 18); + public static final EntityType ITEM_FRAME = getEntityType("item_frame", 18); /** * A flying wither skull projectile. */ - public static final EntityType WITHER_SKULL = getEntityType("wither_skull", 19); + public static final EntityType WITHER_SKULL = getEntityType("wither_skull", 19); /** * Primed TNT that is about to explode. */ - public static final EntityType TNT = getEntityType("tnt", 20); + public static final EntityType TNT = getEntityType("tnt", 20); /** * 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 FALLING_BLOCK = getEntityType("falling_block", 21); /** * 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_ROCKET = getEntityType("firework_rocket", 22); /** * @see Husk */ - public static final EntityType HUSK = getEntityType("husk", 23); + public static final EntityType HUSK = getEntityType("husk", 23); /** * 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 SPECTRAL_ARROW = getEntityType("spectral_arrow", 24); /** * Bullet fired by {@link #SHULKER}. */ - public static final EntityType SHULKER_BULLET = getEntityType("shulker_bullet", 25); + public static final EntityType SHULKER_BULLET = getEntityType("shulker_bullet", 25); /** * Like {@link #FIREBALL} but with added effects. */ - public static final EntityType DRAGON_FIREBALL = getEntityType("dragon_fireball", 26); + public static final EntityType DRAGON_FIREBALL = getEntityType("dragon_fireball", 26); /** * @see ZombieVillager */ - public static final EntityType ZOMBIE_VILLAGER = getEntityType("zombie_villager", 27); + public static final EntityType ZOMBIE_VILLAGER = getEntityType("zombie_villager", 27); /** * @see SkeletonHorse */ - public static final EntityType SKELETON_HORSE = getEntityType("skeleton_horse", 28); + public static final EntityType SKELETON_HORSE = getEntityType("skeleton_horse", 28); /** * @see ZombieHorse */ - public static final EntityType ZOMBIE_HORSE = getEntityType("zombie_horse", 29); + public static final EntityType ZOMBIE_HORSE = getEntityType("zombie_horse", 29); /** * Mechanical entity with an inventory for placing weapons / armor into. */ - public static final EntityType ARMOR_STAND = getEntityType("armor_stand", 30); + public static final EntityType ARMOR_STAND = getEntityType("armor_stand", 30); /** * @see Donkey */ - public static final EntityType DONKEY = getEntityType("donkey", 31); + public static final EntityType DONKEY = getEntityType("donkey", 31); /** * @see Mule */ - public static final EntityType MULE = getEntityType("mule", 32); + public static final EntityType MULE = getEntityType("mule", 32); /** * @see EvokerFangs */ - public static final EntityType EVOKER_FANGS = getEntityType("evoker_fangs", 33); + public static final EntityType EVOKER_FANGS = getEntityType("evoker_fangs", 33); /** * @see Evoker */ - public static final EntityType EVOKER = getEntityType("evoker", 34); + public static final EntityType EVOKER = getEntityType("evoker", 34); /** * @see Vex */ - public static final EntityType VEX = getEntityType("vex", 35); + public static final EntityType VEX = getEntityType("vex", 35); /** * @see Vindicator */ - public static final EntityType VINDICATOR = getEntityType("vindicator", 36); + public static final EntityType VINDICATOR = getEntityType("vindicator", 36); /** * @see Illusioner */ - public static final EntityType ILLUSIONER = getEntityType("illusioner", 37); + public static final EntityType ILLUSIONER = getEntityType("illusioner", 37); /** * @see CommandMinecart */ - public static final EntityType COMMAND_BLOCK_MINECART = getEntityType("command_block_minecart", 40); + public static final EntityType COMMAND_BLOCK_MINECART = getEntityType("command_block_minecart", 40); /** * A placed boat. */ - public static final EntityType BOAT = getEntityType("boat", 41); + public static final EntityType BOAT = getEntityType("boat", 41); /** * @see RideableMinecart */ - public static final EntityType MINECART = getEntityType("minecart", 42); + public static final EntityType MINECART = getEntityType("minecart", 42); /** * @see StorageMinecart */ - public static final EntityType CHEST_MINECART = getEntityType("chest_minecart", 43); + public static final EntityType CHEST_MINECART = getEntityType("chest_minecart", 43); /** * @see PoweredMinecart */ - public static final EntityType FURNACE_MINECART = getEntityType("furnace_minecart", 44); + public static final EntityType FURNACE_MINECART = getEntityType("furnace_minecart", 44); /** * @see ExplosiveMinecart */ - public static final EntityType TNT_MINECART = getEntityType("tnt_minecart", 45); + public static final EntityType TNT_MINECART = getEntityType("tnt_minecart", 45); /** * @see HopperMinecart */ - public static final EntityType HOPPER_MINECART = getEntityType("hopper_minecart", 46); + public static final EntityType HOPPER_MINECART = getEntityType("hopper_minecart", 46); /** * @see SpawnerMinecart */ - public static final EntityType SPAWNER_MINECART = getEntityType("spawner_minecart", 47); - public static final EntityType CREEPER = getEntityType("creeper", 50); - public static final EntityType SKELETON = getEntityType("skeleton", 51); - public static final EntityType SPIDER = getEntityType("spider", 52); - public static final EntityType GIANT = getEntityType("giant", 53); - public static final EntityType ZOMBIE = getEntityType("zombie", 54); - public static final EntityType SLIME = getEntityType("slime", 55); - public static final EntityType GHAST = getEntityType("ghast", 56); - public static final EntityType ZOMBIFIED_PIGLIN = getEntityType("zombified_piglin", 57); - public static final EntityType ENDERMAN = getEntityType("enderman", 58); - public static final EntityType CAVE_SPIDER = getEntityType("cave_spider", 59); - public static final EntityType SILVERFISH = getEntityType("silverfish", 60); - public static final EntityType BLAZE = getEntityType("blaze", 61); - public static final EntityType MAGMA_CUBE = getEntityType("magma_cube", 62); - public static final EntityType ENDER_DRAGON = getEntityType("ender_dragon", 63); - public static final EntityType WITHER = getEntityType("wither", 64); - public static final EntityType BAT = getEntityType("bat", 65); - public static final EntityType WITCH = getEntityType("witch", 66); - public static final EntityType ENDERMITE = getEntityType("endermite", 67); - public static final EntityType GUARDIAN = getEntityType("guardian", 68); - public static final EntityType SHULKER = getEntityType("shulker", 69); - public static final EntityType PIG = getEntityType("pig", 90); - public static final EntityType SHEEP = getEntityType("sheep", 91); - public static final EntityType COW = getEntityType("cow", 92); - public static final EntityType CHICKEN = getEntityType("chicken", 93); - public static final EntityType SQUID = getEntityType("squid", 94); - public static final EntityType WOLF = getEntityType("wolf", 95); - public static final EntityType MOOSHROOM = getEntityType("mooshroom", 96); - public static final EntityType SNOW_GOLEM = getEntityType("snow_golem", 97); - public static final EntityType OCELOT = getEntityType("ocelot", 98); - public static final EntityType IRON_GOLEM = getEntityType("iron_golem", 99); - public static final EntityType HORSE = getEntityType("horse", 100); - public static final EntityType RABBIT = getEntityType("rabbit", 101); - public static final EntityType POLAR_BEAR = getEntityType("polar_bear", 102); - public static final EntityType LLAMA = getEntityType("llama", 103); - public static final EntityType LLAMA_SPIT = getEntityType("llama_spit", 104); - public static final EntityType PARROT = getEntityType("parrot", 105); - public static final EntityType VILLAGER = getEntityType("villager", 120); - public static final EntityType END_CRYSTAL = getEntityType("end_crystal", 200); - public static final EntityType TURTLE = getEntityType("turtle"); - public static final EntityType PHANTOM = getEntityType("phantom"); - public static final EntityType TRIDENT = getEntityType("trident"); - public static final EntityType COD = getEntityType("cod"); - public static final EntityType SALMON = getEntityType("salmon"); - public static final EntityType PUFFERFISH = getEntityType("pufferfish"); - public static final EntityType TROPICAL_FISH = getEntityType("tropical_fish"); - public static final EntityType DROWNED = getEntityType("drowned"); - public static final EntityType DOLPHIN = getEntityType("dolphin"); - public static final EntityType CAT = getEntityType("cat"); - public static final EntityType PANDA = getEntityType("panda"); - public static final EntityType PILLAGER = getEntityType("pillager"); - public static final EntityType RAVAGER = getEntityType("ravager"); - public static final EntityType TRADER_LLAMA = getEntityType("trader_llama"); - public static final EntityType WANDERING_TRADER = getEntityType("wandering_trader"); - public static final EntityType FOX = getEntityType("fox"); - public static final EntityType BEE = getEntityType("bee"); - public static final EntityType HOGLIN = getEntityType("hoglin"); - public static final EntityType PIGLIN = getEntityType("piglin"); - public static final EntityType STRIDER = getEntityType("strider"); - public static final EntityType ZOGLIN = getEntityType("zoglin"); - public static final EntityType PIGLIN_BRUTE = getEntityType("piglin_brute"); - public static final EntityType AXOLOTL = getEntityType("axolotl"); - public static final EntityType GLOW_ITEM_FRAME = getEntityType("glow_item_frame"); - public static final EntityType GLOW_SQUID = getEntityType("glow_squid"); - public static final EntityType GOAT = getEntityType("goat"); - public static final EntityType MARKER = getEntityType("marker"); - public static final EntityType ALLAY = getEntityType("allay"); - public static final EntityType CHEST_BOAT = getEntityType("chest_boat"); - public static final EntityType FROG = getEntityType("frog"); - public static final EntityType TADPOLE = getEntityType("tadpole"); - public static final EntityType WARDEN = getEntityType("warden"); + public static final EntityType SPAWNER_MINECART = getEntityType("spawner_minecart", 47); + public static final EntityType CREEPER = getEntityType("creeper", 50); + public static final EntityType SKELETON = getEntityType("skeleton", 51); + public static final EntityType SPIDER = getEntityType("spider", 52); + public static final EntityType GIANT = getEntityType("giant", 53); + public static final EntityType ZOMBIE = getEntityType("zombie", 54); + public static final EntityType SLIME = getEntityType("slime", 55); + public static final EntityType GHAST = getEntityType("ghast", 56); + public static final EntityType ZOMBIFIED_PIGLIN = getEntityType("zombified_piglin", 57); + public static final EntityType ENDERMAN = getEntityType("enderman", 58); + public static final EntityType CAVE_SPIDER = getEntityType("cave_spider", 59); + public static final EntityType SILVERFISH = getEntityType("silverfish", 60); + public static final EntityType BLAZE = getEntityType("blaze", 61); + public static final EntityType MAGMA_CUBE = getEntityType("magma_cube", 62); + public static final EntityType ENDER_DRAGON = getEntityType("ender_dragon", 63); + public static final EntityType WITHER = getEntityType("wither", 64); + public static final EntityType BAT = getEntityType("bat", 65); + public static final EntityType WITCH = getEntityType("witch", 66); + public static final EntityType ENDERMITE = getEntityType("endermite", 67); + public static final EntityType GUARDIAN = getEntityType("guardian", 68); + public static final EntityType SHULKER = getEntityType("shulker", 69); + public static final EntityType PIG = getEntityType("pig", 90); + public static final EntityType SHEEP = getEntityType("sheep", 91); + public static final EntityType COW = getEntityType("cow", 92); + public static final EntityType CHICKEN = getEntityType("chicken", 93); + public static final EntityType SQUID = getEntityType("squid", 94); + public static final EntityType WOLF = getEntityType("wolf", 95); + public static final EntityType MOOSHROOM = getEntityType("mooshroom", 96); + public static final EntityType SNOW_GOLEM = getEntityType("snow_golem", 97); + public static final EntityType OCELOT = getEntityType("ocelot", 98); + public static final EntityType IRON_GOLEM = getEntityType("iron_golem", 99); + public static final EntityType HORSE = getEntityType("horse", 100); + public static final EntityType RABBIT = getEntityType("rabbit", 101); + public static final EntityType POLAR_BEAR = getEntityType("polar_bear", 102); + public static final EntityType LLAMA = getEntityType("llama", 103); + public static final EntityType LLAMA_SPIT = getEntityType("llama_spit", 104); + public static final EntityType PARROT = getEntityType("parrot", 105); + public static final EntityType VILLAGER = getEntityType("villager", 120); + public static final EntityType END_CRYSTAL = getEntityType("end_crystal", 200); + public static final EntityType TURTLE = getEntityType("turtle"); + public static final EntityType PHANTOM = getEntityType("phantom"); + public static final EntityType TRIDENT = getEntityType("trident"); + public static final EntityType COD = getEntityType("cod"); + public static final EntityType SALMON = getEntityType("salmon"); + public static final EntityType PUFFERFISH = getEntityType("pufferfish"); + public static final EntityType TROPICAL_FISH = getEntityType("tropical_fish"); + public static final EntityType DROWNED = getEntityType("drowned"); + public static final EntityType DOLPHIN = getEntityType("dolphin"); + public static final EntityType CAT = getEntityType("cat"); + public static final EntityType PANDA = getEntityType("panda"); + public static final EntityType PILLAGER = getEntityType("pillager"); + public static final EntityType RAVAGER = getEntityType("ravager"); + public static final EntityType TRADER_LLAMA = getEntityType("trader_llama"); + public static final EntityType WANDERING_TRADER = getEntityType("wandering_trader"); + public static final EntityType FOX = getEntityType("fox"); + public static final EntityType BEE = getEntityType("bee"); + public static final EntityType HOGLIN = getEntityType("hoglin"); + public static final EntityType PIGLIN = getEntityType("piglin"); + public static final EntityType STRIDER = getEntityType("strider"); + public static final EntityType ZOGLIN = getEntityType("zoglin"); + public static final EntityType PIGLIN_BRUTE = getEntityType("piglin_brute"); + public static final EntityType AXOLOTL = getEntityType("axolotl"); + public static final EntityType GLOW_ITEM_FRAME = getEntityType("glow_item_frame"); + public static final EntityType GLOW_SQUID = getEntityType("glow_squid"); + public static final EntityType GOAT = getEntityType("goat"); + public static final EntityType MARKER = getEntityType("marker"); + public static final EntityType ALLAY = getEntityType("allay"); + public static final EntityType CHEST_BOAT = getEntityType("chest_boat"); + public static final EntityType FROG = getEntityType("frog"); + public static final EntityType TADPOLE = getEntityType("tadpole"); + public static final EntityType WARDEN = getEntityType("warden"); @MinecraftExperimental @ApiStatus.Experimental - public static final EntityType CAMEL = getEntityType("camel"); - public static final EntityType BLOCK_DISPLAY = getEntityType("block_display"); - public static final EntityType INTERACTION = getEntityType("interaction"); - public static final EntityType ITEM_DISPLAY = getEntityType("item_display"); + public static final EntityType CAMEL = getEntityType("camel"); + public static final EntityType BLOCK_DISPLAY = getEntityType("block_display"); + public static final EntityType INTERACTION = getEntityType("interaction"); + public static final EntityType ITEM_DISPLAY = getEntityType("item_display"); @MinecraftExperimental @ApiStatus.Experimental - public static final EntityType SNIFFER = getEntityType("sniffer"); - public static final EntityType TEXT_DISPLAY = getEntityType("text_display"); + public static final EntityType SNIFFER = getEntityType("sniffer"); + public static final EntityType TEXT_DISPLAY = getEntityType("text_display"); /** * A fishing line and bobber. */ - public static final EntityType FISHING_BOBBER = getEntityType("fishing_bobber"); + public static final EntityType FISHING_BOBBER = getEntityType("fishing_bobber"); /** * A bolt of lightning. *

* Spawn with {@link World#strikeLightning(Location)}. */ - public static final EntityType LIGHTNING_BOLT = getEntityType("lightning_bolt"); - public static final EntityType PLAYER = getEntityType("player"); + public static final EntityType LIGHTNING_BOLT = getEntityType("lightning_bolt"); + public static final EntityType PLAYER = getEntityType("player"); /** * An unknown entity without an Entity Class * @deprecated only for backwards compatibility, unknown is no longer returned. */ @Deprecated - public static final EntityType UNKNOWN = getEntityType("unknown"); + public static final EntityType UNKNOWN = Bukkit.getUnsafe().getUnkownEntityType(); - private static EntityType getEntityType(@NotNull String key) { + @NotNull + private static EntityType getEntityType(@NotNull String key) { return getEntityType(key, -1); } - private static EntityType getEntityType(@NotNull String key, int typeId) { + @NotNull + private static EntityType getEntityType(@NotNull String key, int typeId) { NamespacedKey namespacedKey = NamespacedKey.minecraft(key); - EntityType entityType = Registry.ENTITY_TYPE.get(namespacedKey); + EntityType entityType = (EntityType) Registry.ENTITY_TYPE.get(namespacedKey); Preconditions.checkNotNull(entityType, "No EntityType found for %s. This is a bug.", namespacedKey); if (typeId > 0) { ID_MAP.put((short) typeId, entityType); @@ -338,7 +341,7 @@ public abstract class EntityType extends OldEnum implements Keyed, T public abstract boolean isAlive(); @Nullable - public abstract Class getEntityClass(); + public abstract Class getEntityClass(); /** * Gets the entity type name. @@ -375,6 +378,7 @@ public abstract class EntityType extends OldEnum implements Keyed, T if (name == null) { return null; } + name = convertLegacy(name); return Registry.ENTITY_TYPE.get(NamespacedKey.fromString(name.toLowerCase(java.util.Locale.ENGLISH))); } @@ -402,6 +406,7 @@ public abstract class EntityType extends OldEnum implements Keyed, T @NotNull @Deprecated public static EntityType valueOf(@NotNull String name) { + name = convertLegacy(name); EntityType entityType = Registry.ENTITY_TYPE.get(NamespacedKey.fromString(name.toLowerCase())); Preconditions.checkArgument(entityType != null, "No EntityType found with the name %s", name); return entityType; @@ -416,4 +421,67 @@ public abstract class EntityType extends OldEnum implements Keyed, T public static EntityType[] values() { 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; + } } diff --git a/src/main/java/org/bukkit/potion/PotionEffectType.java b/src/main/java/org/bukkit/potion/PotionEffectType.java index 70574096..2f87a2f8 100644 --- a/src/main/java/org/bukkit/potion/PotionEffectType.java +++ b/src/main/java/org/bukkit/potion/PotionEffectType.java @@ -290,6 +290,7 @@ public abstract class PotionEffectType implements Keyed { @Deprecated public static PotionEffectType getByName(@NotNull String name) { 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))); } @@ -320,4 +321,33 @@ public abstract class PotionEffectType implements Keyed { */ @Deprecated 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; + } }